Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Login Script 1

Status
Not open for further replies.

DASLG

IS-IT--Management
Mar 14, 2002
81
US
Hello all,
I have been following a few threads about VBS scripting and have started using Mark D. MacLachlan's (thank you very much) login script as a basis. My problem is, the script will not remove the drive letter specified on my test script. I have

WSHNetwork.RemoveNetworkDrive "T:"

wscript.sleep 800

But the drive is not removed. Also how would I remove multiple drives? Would I add a sleep statement after every remove or just one? And one more question, can I add printers based on group association? All in one script?(ok maybe 2 more questions)

Thank you,
Damon
 
Example of adding printer conenction:

Set WshNetwork = CreateObject("WScript.Network")
WshNetwork.AddWindowsPrinterConnection "\\PrintServer1\Xerox300"
WshNetwork.SetDefaultPrinter "\\PrintServer1\Xerox300"


REmove a printer connection:

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.RemovePrinterConnection "\\PrintServer\xerox3006"

or

' VBScript

' Guy Thomas January 2004

' VBScript to Remove a Network Printer
Dim WshPrinter, strPrintPath
strPrintPath = "\\ServerPrint1\HPPrinter"
Set WshPrinter = WScript.CreateObject("WScript.Network")
WshPrinter.RemovePrinterConnection strPrintPath, true, true


MAp Drive:

' VBScript.
Dim net
Set net = CreateObject("WScript.Network")
net.MapNetworkDrive "I:", "\\computer2\public","True"

or

Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
DriveLetter1 = "P:"
RemotePath1 = "\\alan\Drivers"

objNetwork.MapNetworkDrive DriveLetter1, RemotePath1
objShell.PopUp "Drive " & DriveLetter1 & " connected successfully."

Wscript.Quit

' End of Script

' RemoveDrive.vbs - Removes Mapped Network Drive
' Author Guy Thomas ' Version 1.5 - June 6th 2004
' -------------------------------------------------------------'
Option Explicit
Dim objShell, objNetwork, DriveLetter1

DriveLetter1 = "P:"

Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")

objNetwork.RemoveNetworkDrive DriveLetter1
objShell.PopUp "Drive " & DriveLetter1 & " disconnected."

Wscript.Quit

' End of Script




Joseph L. Poandl
MCSE 2003

If your company is in need of experts to examine technical problems/solutions, please contact (Sales@njcomputernetworks.com)
 
Thanks for the reply Joseph. Is there a way to map Printers based on groups? BTW this is how the script that I am using looks.

ON ERROR RESUME NEXT

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
DomainString = "Domain"
UserString = WSHNetwork.UserName

Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Synchronizes the time with Server our NTP Server
WSHShell.Run "NET TIME \\server /set /y"

WSHNetwork.RemoveNetworkDrive "L:",True, True
WSHNetwork.RemoveNetworkDrive "P:",True, True

wscript.sleep 500


'Maps drives needed by all
WSHNetwork.MapNetworkDrive "L:", "\\server\share",True
WSHNetwork.MapNetworkDrive "P:", "\\server\share",True

'Now check for group memberships and map appropriate drives
For Each GroupObj In UserObj.Groups

Select Case GroupObj.Name
'Check for group memberships and take needed action
Case "Group1"
WSHNetwork.MapNetworkDrive "J:", "\\server\share",True
Case "Group2"
WSHNetwork.MapNetworkDrive "K:", "\\server\share",True

End Select

Next


set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing

wscript.quit

I guess I would put the add printer command after the Next statement, is that right? Or can add the statement under the Case group statements so that the printer is created for that group?
 
Nevermind, I figured it out. I just included the Add printer statement after the drive mapping for each group and it worked. I was wondering if anyone knows if you could map drives by IP address? We have a backup site with 1 Domain controller and it is connected to the main site via point-to-point T1 line. I want the script to differentiate between IP addresses so that if a user logs in at the backup site they get mapped to the network shares located there. Anyone have any insight on if this can be done.
 
Hi Daslg,

Glad to see my script is helping you out.

So, if I understand correctly, you want the login script to return the current machines IP address and based on the response you get perform a drive mapping. Is that correct?



I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Wow. A response from the man himself. Once again thanks for the scripts and all the help. I have bookmarked that page for future reference thanks very much. Back to the problem, which you completely understood. So I take it if I specify to read by the third octet(we use 192.168. for all subnets), I would put ThirdOctet=IPAddress (2). Ok this will return the IPAddress being used but how would I then tell the script to map certain drives based on that? Or would I write 3 different scripts? One that finds out the IP Address and based on that calls on one of the two other scripts that would then map drives for that particular subnet. Do you have any recommendations for scripting books? I know I could probably find what I need on the internet but I would like a reference guide to read on the train/bus/car.
 
You can use a Select statement once you have grabbed your third octet.

Code:
Select Case  3rdOctet 
	Case "1"
		WSHNetwork.MapNetworkDrive "X:", "\\server1\Share",True
        Case "2"
		WSHNetwork.MapNetworkDrive "X:", "\\server2\Share",True


End Select

The Windows 2000 Scripting Guide is a good one for reading during a commute. Much of the content is available for free from MS in electronic format. Check out microsoft.com/scripting for some really great resources.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Thanks again for all your help.
 
Hate to reopen a somewhat dead issue but I'm having trouble running a program through this current script. The program we are using is Track-It! 6.01 and we were using a .bat file to run it. Now that everyone has been moved over to the new script I'm having trouble running this command. I tried adding the fields stated below after the Next statement on the above script but it does not seem to be working.

Const ALL_USERS = True

Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install("\\servername\trackit\tiwsmgr.exe /service /audit", , ALL_USERS)

The original line from the batch file is

start \\slgsvr05\trackit\tiwsmgr.exe /service /audit

Any help would be appreciated.
 
I solved the issue by using the below syntax

with createobject("wscript.shell")
.run "\\servername\trackit\tiwsmgr.exe /service /audit"
end with

Thanks anyway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top