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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Computer Will Not Run Login Script

Status
Not open for further replies.

Arsynic

MIS
Jun 17, 2003
141
I only want one computer on the network to run a script to network it to a particular printer. The users logging into the computer have roaming profiles so I can't just put the script in the startup folder because it will move from one computer to the next due to the roaming profiles.

So I just created a new Organizational Unit and moved the computer into it. I then created a new Group Policy named "Printing" and put this login script in it:

Set WshNetwork = WScript.CreateObject("WScript.Network")
WshNetwork.AddPrinterConnection "LPT1", "\\Server\Print1"

Well it's not working and I don't know why. The script works because I tested it on my local machine. However, it won't run on the computer I want it to run on. What's the deal?
 
I can't help much with the VB part of this but instead of having them in an OU you could just add the script to their Profile in AD. To do this copy the script you want to run to your \\server\netlogon directory and place the name of the file ex. file.bat in the Profile->Logon Script box.

---------------------------------------
 
It's roaming users and they move from computer to computer. I only want it to run on a single computer. It's only one computer I'm concerned with. Is there a certain amount of time that it takes for the computer to recognize the script from the DC?
 
The problem you are having is that login scripts are a user setting in Group Policy and you are trying to apply it to the Computer. Startup/Shutdown scripts apply to the PC.

You will need to change the logic of your login script and have it validate the local IP address or machine name to do the mapping. Set this as a login script for your users and not the PC.

You can do it like this:
Code:
Set WSHShell = CreateObject("WScript.shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set env = WSHShell.environment("Process")
Computername = env.item("computername")

If Computername = "machinename" Then 
   WshNetwork.AddPrinterConnection "LPT1", "\\Server\Print1"
End If

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

Regards,

Mark
 
I did mine as a startup script, not a login script, sorry. I can't apply it to users because I only want it to kick in when they log in to a particular computer, not all of them. If I apply the script to login, then it will kick in for all users. But I like your code. Originially I wanted to use something like your code instead of creating a whole new OU to put the computer in.
 
Also, what do I need to replace in the script besides \\server\print1? Do I need to replace "computername" with the actual computer name?
 
Computername would be the name of the ONE machine you want this to execute on. Doing it this way you CAN set it as a login script. It will have NO affect an a user UNLESS they are logged into that one machine.

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

Regards,

Mark
 
It's not working. I'm sure I put the code in right. It won't even work when I try to execute it on the machine directly. Let's say the local computer's name is "Dog" and the computer with the printer connected to it is named "Cat" and the printer name is "CatPrinter". I typed the code like this:
Code:
Set WSHShell = CreateObject("WScript.shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set env = WSHShell.environment("Process")
Computername = env.item("Dog")

If Computername = "machinename" Then 
   WshNetwork.AddPrinterConnection "LPT1", "\\Cat\CatPrinter"
End If
 
You made the edits int he wrong place. here you go:

Code:
Set WSHShell = CreateObject("WScript.shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set env = WSHShell.environment("Process")
Computername = env.item("computername")

If Computername = "dog" Then 
   WshNetwork.AddPrinterConnection "LPT1", "\\cat\CatPrinter"
End If

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

Regards,

Mark
 
One more thought is that you might need to work with the case for the computername. Like this:

Code:
If lcase(Computername) = "dog" Then

or this

Code:
If Ucase(Computername) = "DOG" Then

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

Regards,

Mark
 
Well, obviously it takes a while for the script to kick in. It wasn't working last night (yes, I stayed late), but when I logged in this morning, it works fine. Thanks a lot. I learned a whole lot.
 
Cool. You might want to set in your GPO the background refresh rate. That could help spped up your seeing changes to a GPO get applied.

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

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top