Page 1 of 1
How to map drive and open folder
Posted: 24 Jul 2009 13:56
by brianpaul
I can map a drive and open the folder by doing the following...
C:\Windows\System32\net use s: \\Server\Share
explorer s:
But I want to do this all in one command so I can create a link on a desktop that will map and open the shared folder. In other words, I want to have an icon on the desktop that you click and it opens up the S drive folder. I know I can do it by creating a link to a batch file, but I would like to do it right in the shortcut. Any ideas on how this can be done?
Posted: 27 Jul 2009 06:39
by RElliott63
Brian,
Your command to connect is like this:
Code: Select all
Net Use %Drive% /Delete 1>Nul 2>Nul
Net Use %Drive% \\location\H$ 1>NUL 2>NUL
I would assume that you don't need a UserID/Password if it's on your own machine... if not, you might have to add the /User and password to the command.
If on a multi-person computer -- I would add the /Delete command ahead of this to make sure you're connecting to the correct drive. (Just a precaution)
How to map drive and OPEN FOLDER
Posted: 27 Jul 2009 08:37
by brianpaul
Ok, let me try to be a little clearer. I want to do two things...
1. Map a drive
2. Open the folder of that drive
PLEASE note that I know how to do this. All I need to so is this...
C:\Windows\System32\net use s: \\Server\Share
explorer s:
The problem is, I don't want to do this in a batch file, I want to do this in a shortcut. By shortcut I mean, right click on your desktop and choose New/Shortcut. When asked for the path, you can then enter a command, but it cannot be more than one line.
In vb6, you can have multiple lines of code on one line and just separate them with colons. I'm wondering if dos has such a character that says "put this on the next line"? Anyway, I think I found the answer, the character needed is the pipes ("|"). I tried this...
C:\Windows\System32\net use s: \\Server\Share| explorer s:
And it works, but it doesn't work if I put it into a shortcut. To get it to work in a shortcut, I had to do this...
C:\WINDOWS\system32\cmd.exe /c "c:\windows\system32\net.exe use /d S:| C:\WINDOWS\system32\net.exe use s: \\server\share| explorer S:"
The only problem that I'm having now is that the 2nd command does not wait for the first command to finish.
Posted: 27 Jul 2009 15:06
by avery_larry
Haven't tried it, but you're looking for && (or possibly a single & if it's on the command line) . . .
C:\Windows\System32\net use s: \\Server\Share && explorer s:
Something like that might work, probably with the cmd.exe /c prepended.
Posted: 27 Jul 2009 17:51
by brianpaul
Thanks Avery, that's a big help! You're right, && works, but it doesn't go onto the next command if the current command doesn't succeed. The command following && will be executed only if the first command is successful. I would like to start with a "net use /d S:" statement to delete the S drive if it exists. The problem is, if it doesn't exist, the command will fail and because the statement is followed by &&, it will not continue after that statement. What I have done is this...
C:\WINDOWS\system32\cmd.exe /c "c:\windows\system32\net.exe use /d S:| C:\WINDOWS\system32\net.exe use s: \\server\share&& explorer S:"
So, after deleting the S drive mapping, then I use "|" so that the commands will continue even if S wasn't mapped. Next, after the middle statement, which maps the S drive, I then use the && before opening the S drive folder. This seems to work, but I'm afraid that the S drive mapping might not delete in time and then the second statement will fail.
What I really need is a character that will wait until the command finishes and continue on even if the command failed. && will only continue on if it succeeds, but I don't think there is a dos separator character that will wait for the command to finish in a failed state and then continue on. If anyone can think of a way to do this, it would be very much appreciated!
this might help you
Posted: 16 Aug 2009 16:57
by subhashchy
I think this is what you know but missing...
cmd.exe /c start /w net use s: \\server\share && explorer S:
Start is a command line not a windows command so we have to excute it via command prompt, cmd /c will continue this command and will exit auto.
where S: is the maped drive and start /w paramaeter starts this command in a new window ,wait till it finishes and then excute explorer.exe s:.
If S: is not monuted it will mount, if already mounted then just excute explorer s:
hope this helps.