WSH mapping drives leaves default path set
-
08-07-2019 - |
Question
I wrote the following javascript to put in my startup folder to work around some problems with mapping drives. Unfortunately it has the side effect of starting command prompts with H:\ as current directory. How can I get around this?
var objNetwork = WScript.CreateObject("WScript.Network");
/* Remove Network Drives */
try {
objNetwork.RemoveNetworkDrive("H:", true, true);
} catch (e) {}
try {
objNetwork.RemoveNetworkDrive("Y:", true, true);
} catch (e) {}
try {
objNetwork.RemoveNetworkDrive("Z:", true, true);
} catch (e) {}
/* Recreate Network Drives */
objNetwork.MapNetworkDrive ("H:", "\\\\server1\\home", false);
objNetwork.MapNetworkDrive ("Y:", "\\\\server2\\source", false, "user", "pass");
objNetwork.MapNetworkDrive ("Z:", "\\\\server3\\source", false, "user", "pass");
Solution
I actually worked this out from the suggested alternative questions, but it was different enough I thought I'd finish posting and answer my own question.
Bascially, the %HOMEDRIVE% was set to H:\, but since H:\ did not exist before I wrote my script, it wasn't getting set in the command prompt.
You can add an Autorun to the command prompt to change to C: (or wherever) before it starts. More details here: http://windowsxp.mvps.org/autoruncmd.htm
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow