![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | I need to MAP a drive to the local computer I'm working on a logon script. If the first condition is true, I need to map the drive to the local computer, and share is named Procede. I can't seem to figure out the correct syntax for this part \\"%strComputer%"\Procede I've tried this various ways and can't seem to come up with the correct syntax. +++++++++++++++++ If (strComputer) = "ITMANAGER" Then WSHNetwork.MapNetworkDrive "P:", "\\"%strComputer%"\Procede",True Else WSHNetwork.MapNetworkDrive "P:", "\\prosperity\SharedData\CommonShare",True End if +++++++++++++++++ Your help would be appreciated! Thanks Kelvin Server 2003 XP Pro |
My System Specs![]() |
| | #2 (permalink) |
| | Re: I need to MAP a drive to the local computer Also, how do I display the value of strComputer? "Kelvin" <me@xxxxxx> wrote in message news:ufgLEsuBKHA.528@xxxxxx Quote: > I'm working on a logon script. > > If the first condition is true, I need to map the drive to the local > computer, and share is named Procede. > I can't seem to figure out the correct syntax for this part > \\"%strComputer%"\Procede > I've tried this various ways and can't seem to come up with the correct > syntax. > > +++++++++++++++++ > If (strComputer) = "ITMANAGER" Then > WSHNetwork.MapNetworkDrive "P:", "\\"%strComputer%"\Procede",True > Else > WSHNetwork.MapNetworkDrive "P:", > "\\prosperity\SharedData\CommonShare",True > End if > +++++++++++++++++ > > Your help would be appreciated! > > Thanks > > Kelvin > > Server 2003 > XP Pro > |
My System Specs![]() |
| | #3 (permalink) |
| | Re: I need to MAP a drive to the local computer Kelvin wrote: Quote: > I'm working on a logon script. > > If the first condition is true, I need to map the drive to the local > computer, and share is named Procede. > I can't seem to figure out the correct syntax for this part > \\"%strComputer%"\Procede > I've tried this various ways and can't seem to come up with the correct > syntax. > > +++++++++++++++++ > If (strComputer) = "ITMANAGER" Then > WSHNetwork.MapNetworkDrive "P:", "\\"%strComputer%"\Procede",True > Else > WSHNetwork.MapNetworkDrive "P:", > "\\prosperity\SharedData\CommonShare",True > End if > +++++++++++++++++ > > Your help would be appreciated! ==== Set WSHNetwork = CreateObject("Wscript.Network") strComputer = WSHNetwork.ComputerName If (UCase(strComputer = "ITMANAGER") Then WSHNetwork.MapNetworkDrive "P:", "\\" & strComputer & "\Procede", True Else WSHNetwork.MapNetworkDrive "P:", "\\prosperity\SharedData\CommonShare", True End If ====== I use the UCase function to make the comparison case insensitive. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #4 (permalink) |
| | Re: I need to MAP a drive to the local computer In a logon script you can display information to the user with MsgBox statements. This halts the execution of the script until the user clicks "OK". For example: Call MsgBox("Computer is " & strComputer) My fear is that the user may have walked away, expecting the logon process to be complete when they return, so I sometimes use the Popup method of the wshShell object, which has a timeout parameter. For example: Set objShell = CreateObject("Wscript.Shell") objShell.Popup "Computer: " & strComputer, 20, "My Title" This shows the message for 20 seconds. The message quits if the user clicks OK, or 20 seconds have elapsed, whichever is first. -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- "Kelvin" <me@xxxxxx> wrote in message news:upt%23vAvBKHA.688@xxxxxx Quote: > Also, how do I display the value of strComputer? > > > "Kelvin" <me@xxxxxx> wrote in message > news:ufgLEsuBKHA.528@xxxxxx Quote: >> I'm working on a logon script. >> >> If the first condition is true, I need to map the drive to the local >> computer, and share is named Procede. >> I can't seem to figure out the correct syntax for this part >> \\"%strComputer%"\Procede >> I've tried this various ways and can't seem to come up with the correct >> syntax. >> >> +++++++++++++++++ >> If (strComputer) = "ITMANAGER" Then >> WSHNetwork.MapNetworkDrive "P:", "\\"%strComputer%"\Procede",True >> Else >> WSHNetwork.MapNetworkDrive "P:", >> "\\prosperity\SharedData\CommonShare",True >> End if >> +++++++++++++++++ >> >> Your help would be appreciated! >> >> Thanks >> >> Kelvin >> >> Server 2003 >> XP Pro >> > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: I need to MAP a drive to the local computer "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in message news:OVKHyGvBKHA.1488@xxxxxx Quote: > Kelvin wrote: > Quote: >> I'm working on a logon script. >> >> If the first condition is true, I need to map the drive to the local >> computer, and share is named Procede. >> I can't seem to figure out the correct syntax for this part >> \\"%strComputer%"\Procede >> I've tried this various ways and can't seem to come up with the correct >> syntax. >> >> +++++++++++++++++ >> If (strComputer) = "ITMANAGER" Then >> WSHNetwork.MapNetworkDrive "P:", "\\"%strComputer%"\Procede",True >> Else >> WSHNetwork.MapNetworkDrive "P:", >> "\\prosperity\SharedData\CommonShare",True >> End if >> +++++++++++++++++ >> >> Your help would be appreciated! > Perhaps: > ==== > Set WSHNetwork = CreateObject("Wscript.Network") > strComputer = WSHNetwork.ComputerName > If (UCase(strComputer = "ITMANAGER") Then > WSHNetwork.MapNetworkDrive "P:", "\\" & strComputer & "\Procede", True > Else > WSHNetwork.MapNetworkDrive "P:", "\\prosperity\SharedData\CommonShare", > True > End If > ====== > I use the UCase function to make the comparison case insensitive. > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > It should be: If (UCase(strComputer) = "ITMANAGER") Then -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #6 (permalink) |
| | Re: I need to MAP a drive to the local computer I got it working thanks to you. Thanks for the hint about UCase I did a little testing and can see how that makes a difference... Thanks Kelvin "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in message news:u8IIFQvBKHA.5992@xxxxxx Quote: > > "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in > message news:OVKHyGvBKHA.1488@xxxxxx Quote: >> Kelvin wrote: >> Quote: >>> I'm working on a logon script. >>> >>> If the first condition is true, I need to map the drive to the local >>> computer, and share is named Procede. >>> I can't seem to figure out the correct syntax for this part >>> \\"%strComputer%"\Procede >>> I've tried this various ways and can't seem to come up with the correct >>> syntax. >>> >>> +++++++++++++++++ >>> If (strComputer) = "ITMANAGER" Then >>> WSHNetwork.MapNetworkDrive "P:", "\\"%strComputer%"\Procede",True >>> Else >>> WSHNetwork.MapNetworkDrive "P:", >>> "\\prosperity\SharedData\CommonShare",True >>> End if >>> +++++++++++++++++ >>> >>> Your help would be appreciated! >> Perhaps: >> ==== >> Set WSHNetwork = CreateObject("Wscript.Network") >> strComputer = WSHNetwork.ComputerName >> If (UCase(strComputer = "ITMANAGER") Then >> WSHNetwork.MapNetworkDrive "P:", "\\" & strComputer & "\Procede", True >> Else >> WSHNetwork.MapNetworkDrive "P:", >> "\\prosperity\SharedData\CommonShare", True >> End If >> ====== >> I use the UCase function to make the comparison case insensitive. >> >> -- >> Richard Mueller >> MVP Directory Services >> Hilltop Lab - http://www.rlmueller.net >> -- >> > Sorry, I see I missed a closing parentheses when I used the UCase > function. It should be: > > If (UCase(strComputer) = "ITMANAGER") Then > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > |
My System Specs![]() |
| | #7 (permalink) |
| | Re: I need to MAP a drive to the local computer Thanks, I was just wanting to use this for testing purposes, but I'll keep the notes in case I want the user to see the message. Thanks Kelvin "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in message news:uwU5xKvBKHA.3368@xxxxxx Quote: > In a logon script you can display information to the user with MsgBox > statements. This halts the execution of the script until the user clicks > "OK". For example: > > Call MsgBox("Computer is " & strComputer) > > My fear is that the user may have walked away, expecting the logon process > to be complete when they return, so I sometimes use the Popup method of > the wshShell object, which has a timeout parameter. For example: > > Set objShell = CreateObject("Wscript.Shell") > objShell.Popup "Computer: " & strComputer, 20, "My Title" > > This shows the message for 20 seconds. The message quits if the user > clicks OK, or 20 seconds have elapsed, whichever is first. > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > "Kelvin" <me@xxxxxx> wrote in message > news:upt%23vAvBKHA.688@xxxxxx Quote: >> Also, how do I display the value of strComputer? >> >> >> "Kelvin" <me@xxxxxx> wrote in message >> news:ufgLEsuBKHA.528@xxxxxx Quote: >>> I'm working on a logon script. >>> >>> If the first condition is true, I need to map the drive to the local >>> computer, and share is named Procede. >>> I can't seem to figure out the correct syntax for this part >>> \\"%strComputer%"\Procede >>> I've tried this various ways and can't seem to come up with the correct >>> syntax. >>> >>> +++++++++++++++++ >>> If (strComputer) = "ITMANAGER" Then >>> WSHNetwork.MapNetworkDrive "P:", "\\"%strComputer%"\Procede",True >>> Else >>> WSHNetwork.MapNetworkDrive "P:", >>> "\\prosperity\SharedData\CommonShare",True >>> End if >>> +++++++++++++++++ >>> >>> Your help would be appreciated! >>> >>> Thanks >>> >>> Kelvin >>> >>> Server 2003 >>> XP Pro >>> >> > |
My System Specs![]() |
| | #8 (permalink) |
| | Re: I need to MAP a drive to the local computer Hi Richard Would you look at one more thing for me? Ulitmatley this is what I'm trying to get to. "If mid((UCase(strComputer)), 3, 2 = LT) Then" I'll actually use "P:" for both drives in the end. --------------------------------------------------------------- If mid((UCase(strComputer)), 3, 2 = LT) Then WSHNetwork.MapNetworkDrive "O", "\\"&strComputer&"\Procede",True Else WSHNetwork.MapNetworkDrive "P:", "\\prosperity\SharedData\CommonShare",True End if --------------------------------------------------------------- My computers name is "itmanager" and for some reason this IF statement answers true even using the mid statement and IT as above. I'm stumped as to why it answers true. My script is based on this code http://www.tek-tips.com/faqs.cfm?fid=5798 Any help would be appreciated!!! Thanks Kelvin This is the complete script I'm testing with +++++++++++++++++++++ ON ERROR RESUME NEXT Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path Set WSHShell = CreateObject("WScript.Shell") Set WSHNetwork = CreateObject("WScript.Network") ' Automatically grab the user's domain name DomainString = Wshnetwork.UserDomain ' Find the Windows Directory WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%") ' Grab the user name UserString = WSHNetwork.UserName ' Bind to the user object to get user name and check for group memberships later Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString) ' Grab the computer name for use in add-on code later strComputer = WSHNetwork.ComputerName ' Disconnect ALL mapped drives Set clDrives = WshNetwork.EnumNetworkDrives For i = 0 to clDrives.Count -1 Step 2 WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True Next Call MsgBox("Computer is " & strComputer) ' the value is still ITMANAGER here ' Give the PC time to do the disconnect, wait 300 milliseconds wscript.sleep 300 'Map drives needed by all ' WSHNetwork.MapNetworkDrive "U:", "\\prosperity\userData\" & UserString & "\My Documents",True Document.Write(strComputer) If mid((UCase(strComputer)), 3, 2 = "LT") Then WSHNetwork.MapNetworkDrive "O:", "\\"&strComputer&"\Procede",True Else WSHNetwork.MapNetworkDrive "P:", "\\prosperity\SharedData\CommonShare",True End if Call MsgBox("Computer is " & strComputer) ' the value is still ITMANAGER here 'Clean Up Memory We Used set UserObj = Nothing set GroupObj = Nothing set WSHNetwork = Nothing set DomainString = Nothing set WSHSHell = Nothing Set WSHPrinters = Nothing Set strComputer = Nothing ' I added this thinking the value wasn't getting cleared. Not sure it's written correctly ' I just added this line but it doesn't run Call MsgBox("Computer is " & strComputer) 'Quit the Script wscript.quit +++++++++++++++++++++ |
My System Specs![]() |
| | #9 (permalink) |
| | Re: I need to MAP a drive to the local computer "Kelvin" <me@xxxxxx> wrote in message news:Ol9Bz1vBKHA.5780@xxxxxx Quote: > Hi Richard > > Would you look at one more thing for me? > Ulitmatley this is what I'm trying to get to. "If > mid((UCase(strComputer)), 3, 2 = LT) Then" > I'll actually use "P:" for both drives in the end. > --------------------------------------------------------------- > If mid((UCase(strComputer)), 3, 2 = LT) Then > WSHNetwork.MapNetworkDrive "O", > "\\"&strComputer&"\Procede",True > Else > WSHNetwork.MapNetworkDrive "P:", > "\\prosperity\SharedData\CommonShare",True > End if > --------------------------------------------------------------- > > My computers name is "itmanager" and for some reason this IF statement > answers true even using the mid statement and IT as above. > > I'm stumped as to why it answers true. > > My script is based on this code http://www.tek-tips.com/faqs.cfm?fid=5798 > > Any help would be appreciated!!! > > Thanks > > Kelvin > > This is the complete script I'm testing with > +++++++++++++++++++++ > ON ERROR RESUME NEXT > > Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, > Path > > Set WSHShell = CreateObject("WScript.Shell") > Set WSHNetwork = CreateObject("WScript.Network") > ' Automatically grab the user's domain name > DomainString = Wshnetwork.UserDomain > ' Find the Windows Directory > WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%") > ' Grab the user name > UserString = WSHNetwork.UserName > ' Bind to the user object to get user name and check for group memberships > later > Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString) > ' Grab the computer name for use in add-on code later > strComputer = WSHNetwork.ComputerName > ' Disconnect ALL mapped drives > Set clDrives = WshNetwork.EnumNetworkDrives > For i = 0 to clDrives.Count -1 Step 2 > WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True > Next > > Call MsgBox("Computer is " & strComputer) > ' the value is still ITMANAGER here > > ' Give the PC time to do the disconnect, wait 300 milliseconds > wscript.sleep 300 > > 'Map drives needed by all > ' WSHNetwork.MapNetworkDrive "U:", "\\prosperity\userData\" & UserString & > "\My Documents",True > Document.Write(strComputer) > > If mid((UCase(strComputer)), 3, 2 = "LT") Then > > WSHNetwork.MapNetworkDrive "O:", > "\\"&strComputer&"\Procede",True > Else > WSHNetwork.MapNetworkDrive "P:", > "\\prosperity\SharedData\CommonShare",True > End if > > Call MsgBox("Computer is " & strComputer) > ' the value is still ITMANAGER here > > 'Clean Up Memory We Used > set UserObj = Nothing > set GroupObj = Nothing > set WSHNetwork = Nothing > set DomainString = Nothing > set WSHSHell = Nothing > Set WSHPrinters = Nothing > Set strComputer = Nothing ' I added this thinking the value wasn't getting > cleared. Not sure it's written correctly > > ' I just added this line but it doesn't run > Call MsgBox("Computer is " & strComputer) > > 'Quit the Script > wscript.quit > +++++++++++++++++++++ troubleshooting very difficult. The reason the last Call MsgBox statement does not run is probably because the statement: Set strComputer = Nothing raises an error. The Set is only appropriate for objects, so it should not be used for DomainString or strComputer. Really, it's not needed for any of the objects at the end, as the object references will be destroyed anyway when the script ends. If it were necessary to clear strComputer (it is not in this case), you would use: strComputer = "" There is also an error in your use of the Mid function. The parentheses are in the wrong places. It should be: If (mid(UCase(strComputer), 3, 2) = "LT") Then Again, the error was ignored because of "On Error Resume Next". -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net -- |
My System Specs![]() |
| | #10 (permalink) |
| | Re: I need to MAP a drive to the local computer Hi Richard, Thanks a million for your help, a programmer I'm not, so I really appreciate your help! I fixed the Mid syntax like you suggested and that part work correct. I removed the On Error line, now I can see there's an error that was not showing because of the On Error line. ---------------- Line: 20 Char: 1 Error: The parameter is incorrect Code: 80070057 Source: WSHNetwork.RemoveNetworkDrive ---------------- These are lines 19 to 21. ---------------- For i = 0 to clDrives.Count -1 Step 2 WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True Next ---------------- Any help would be appreciated! Kelvin "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxx> wrote in message news:%23K96EBxBKHA.5780@xxxxxx Quote: > > "Kelvin" <me@xxxxxx> wrote in message > news:Ol9Bz1vBKHA.5780@xxxxxx Quote: >> Hi Richard >> >> Would you look at one more thing for me? >> Ulitmatley this is what I'm trying to get to. "If >> mid((UCase(strComputer)), 3, 2 = LT) Then" >> I'll actually use "P:" for both drives in the end. >> --------------------------------------------------------------- >> If mid((UCase(strComputer)), 3, 2 = LT) Then >> WSHNetwork.MapNetworkDrive "O", >> "\\"&strComputer&"\Procede",True >> Else >> WSHNetwork.MapNetworkDrive "P:", >> "\\prosperity\SharedData\CommonShare",True >> End if >> --------------------------------------------------------------- >> >> My computers name is "itmanager" and for some reason this IF statement >> answers true even using the mid statement and IT as above. >> >> I'm stumped as to why it answers true. >> >> My script is based on this code http://www.tek-tips.com/faqs.cfm?fid=5798 >> >> Any help would be appreciated!!! >> >> Thanks >> >> Kelvin >> >> This is the complete script I'm testing with >> +++++++++++++++++++++ >> ON ERROR RESUME NEXT >> >> Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, >> Path >> >> Set WSHShell = CreateObject("WScript.Shell") >> Set WSHNetwork = CreateObject("WScript.Network") >> ' Automatically grab the user's domain name >> DomainString = Wshnetwork.UserDomain >> ' Find the Windows Directory >> WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%") >> ' Grab the user name >> UserString = WSHNetwork.UserName >> ' Bind to the user object to get user name and check for group >> memberships later >> Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString) >> ' Grab the computer name for use in add-on code later >> strComputer = WSHNetwork.ComputerName >> ' Disconnect ALL mapped drives >> Set clDrives = WshNetwork.EnumNetworkDrives >> For i = 0 to clDrives.Count -1 Step 2 >> WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True >> Next >> >> Call MsgBox("Computer is " & strComputer) >> ' the value is still ITMANAGER here >> >> ' Give the PC time to do the disconnect, wait 300 milliseconds >> wscript.sleep 300 >> >> 'Map drives needed by all >> ' WSHNetwork.MapNetworkDrive "U:", "\\prosperity\userData\" & UserString >> & "\My Documents",True >> Document.Write(strComputer) >> >> If mid((UCase(strComputer)), 3, 2 = "LT") Then >> >> WSHNetwork.MapNetworkDrive "O:", >> "\\"&strComputer&"\Procede",True >> Else >> WSHNetwork.MapNetworkDrive "P:", >> "\\prosperity\SharedData\CommonShare",True >> End if >> >> Call MsgBox("Computer is " & strComputer) >> ' the value is still ITMANAGER here >> >> 'Clean Up Memory We Used >> set UserObj = Nothing >> set GroupObj = Nothing >> set WSHNetwork = Nothing >> set DomainString = Nothing >> set WSHSHell = Nothing >> Set WSHPrinters = Nothing >> Set strComputer = Nothing ' I added this thinking the value wasn't >> getting cleared. Not sure it's written correctly >> >> ' I just added this line but it doesn't run >> Call MsgBox("Computer is " & strComputer) >> >> 'Quit the Script >> wscript.quit >> +++++++++++++++++++++ > I'd recommend removing the "On Error Resume Next" statement, as it makes > troubleshooting very difficult. The reason the last Call MsgBox statement > does not run is probably because the statement: > > Set strComputer = Nothing > > raises an error. The Set is only appropriate for objects, so it should not > be used for DomainString or strComputer. Really, it's not needed for any > of the objects at the end, as the object references will be destroyed > anyway when the script ends. If it were necessary to clear strComputer (it > is not in this case), you would use: > > strComputer = "" > > There is also an error in your use of the Mid function. The parentheses > are in the wrong places. It should be: > > If (mid(UCase(strComputer), 3, 2) = "LT") Then > > Again, the error was ignored because of "On Error Resume Next". > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Local computer policy - computer usage hours | Vista General | |||
| Set Local Computer Description | VB Script | |||
| computer connecting to local only | Network & Sharing | |||
| trouble moving files from local drive to network drive | Vista networking & sharing | |||
| missing hard drive C (local drive) icon | Vista General | |||