Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

On a computer I'm not an administrator on, there is a startup file (.cmd file in C:\Documents and Settings\All Users\Start Menu\Programs\Startup) for all users. It does several things I don't like, so I have created my own .cmd file which I have placed in C:\Documents and Settings\[user]\Start Menu\Programs\Startup.

I want my code to run after the system wide, because my program first undoes the network mappings the system wide file did, and then replaces it with my own network mappings. How can I make my program wait and start as soon as the system wide one is done? (I cannot remove or edit the system wide file).


EDIT: The time that the system wide file takes to runs varies and I would like my file to run right after. The "If Exists" method seems a little to contingent since the system wide script can change or a file could be moved. I am hoping to give my script to a few of my coworkers, so hoping to have it work without me having to update anything. Also, being a linux guy, I don't know cmd code, so please write out any coding suggestions.

share|improve this question
up vote 2 down vote accepted

What your trying to do is a little difficult if you don't have access to the "All Users" start up .bat file if you did all you would have to do is edit it so that after all commands were executed you would

"call Mycoolbatchfile.bat" 

As this is not an option my solution would be to code the following in AutoIT

Global $SystemWideScript = "Admin.bat"

Func MountNetworkDrv($drv,$path)
    ShellExecute(@SystemDir & "\net.exe ","use " & $drv & " " & $path,"","",@SW_HIDE)

While 1
    For $i = 1 To 100

        ;Wait for the Batch script to finish executing
If ProcessExists($SystemWideScript) = 0 Then

    ;The system wide "All Users" batch script is not running so we can execute
MsgBox(0,"Custom Network Drives","I Cannot detect " & $SystemWideScript & " running so i'm executing")




This is just my view on the issue (one of many).

share|improve this answer

I would use the Task Scheduler (Start -> All Programs -> Accessories -> System Tools) if you have Windows Vista / Windows 7. You can tell Windows to run your .cmd a specified amount of time after login, such as 30 seconds.

share|improve this answer
I definitely recommend this approach as well. – Joshua Jun 7 '10 at 14:36
@Dan If you need it to run immediately after the global script, the only way to know when it exits is to know the process name and watch for it's exit (which you can do from the task scheduler, trigger / on event / application / process exit), otherwise simply waiting a maximal amount of time will work regardless of the global scripts's name. – Darth Android Jun 8 '10 at 9:08

as you mentioned that you want to wait until the network mappings. @Mike Fitzpatrick is correct.

REM check if the filesystem has been mounted
IF EXIST L:\somefile GOTO okay
PING -n 2 > nul
goto start

Note that ping -n 2 > nul is for waiting some time in windows.

share|improve this answer
note: the waiting time is to prevent constant looping of batch file – bubu Jun 7 '10 at 14:29
I'm still worried about the system startup file changing, which could nullify my script... but if there isn't a better alternative... Is there a way to make this have a catch that >15 seconds will automatically go to :okay? Also, can I do this on a folder instead of a file? – Jarvin Jun 7 '10 at 14:45
just change -n 2 to -n 15, then remove goto start i think you need to do that on a file – bubu Jun 7 '10 at 15:23

I realize you're looking for a technical solution, and there are several great recommendations above, but first, you might want to consider just talking to your IT department and seeing if they could adjust things to not annoy you in the first place, particularly if other coworkers want this changed, too. I imagine they might not take lightly to you undoing on your own the settings they're implementing.

If you do however decide to forge ahead with this, one possibility would be to put a shortcut to it in the start menu's startup folder. Items in that folder do not run until Explorer starts, and usually explorer doesn't start until after startup scripts have run.

Another method would be to just have sleep 10 at the beginning of your batch file. The sleep command isn't built into windows, but can be downloaded as part of the windows server administration tools.

share|improve this answer

Do an if exist on some file you know exists on the last mapped drive that you don't want mapped, loop (with a few seconds pause) until it does exist, then do the rest of your script.


IF EXIST works fine with just a root folder so you can see if a drive letter is mounted without having to worry about a particular file being on that drive. (Less contingent)

I like the @bubu's use of ping to introduce the delay but @nhinkle's suggestion to install sleep is cleaner.

Based on @bubu's code:

REM optional initial sleep
sleep 15
REM check if the filesystem has been mounted
sleep 5
goto start
share|improve this answer
You can see that i am one of the bastard operators from hell. I agree though, that using "sleep" is neater. – bubu Jun 8 '10 at 17:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .