Link to home
Start Free TrialLog in
Avatar of dmcoop
dmcoopFlag for United States of America

asked on

Problems Getting New Logon Script & New GPO to Work

I have a new logon script I am trying to get to run when a user logs onto the domain.  The script works fine when I run it locally on a computer.  However when I try to have it run by group policy from the DC it does not work.  No errors are generated on the server or computer (that I can tell).

Here is what I have done (server side & PC side):

- Created a new GPO and linked it to my domain.

- Added a test user to the Security Filtering section for this new policy to be enforced on him.

- Copied my new script and its corresponding files to the c:\winnt\sysvol\domain\policies\{GUID}\user\scripts\logon folder.

- On the new policy under: User Configuration – Windows Settings – Scripts – Logon . . . I have the new script added under scripts.

- Ran gpupdate /force on the target PC.  Also rebooted the PC after that failed.

Here is the new script – it is a network printer script:

'******************************************************************************
'******************************************************************************
'**          Printer mapping
'******************************************************************************
'******************************************************************************
on error resume next
Dim objGroupList, objUser, objShell, strGroup, objNet, strNTName
Dim strNetBIOSDomain, strHomeDrive, strHomeShare, CurrentUser, aPrinter, x
Dim PrnList, fso, WshShell, WshNetwork, PrinterPath, LogonPath, strGroup1
Dim strUserName, Return
const fsoForReading = 1

Set objNet = CreateObject("WScript.Network")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
LogonPath = fso.GetParentFolderName(WScript.ScriptFullName)

call Delprinters
call Mapprinters

'************
'Remove Printers
'************
sub Delprinters()
Dim errorObject
'Set errorObject = CreateObject("Wscript.Error") <-> I disabled this for another issue.
If fso.FileExists(LogonPath & "\Printers_remove.csv") Then
  Set prnlist = fso.OpenTextFile(logonpath & "\Printers_remove.csv", fsoForReading)
  aPrinter = Split(prnlist.Readall,vbcrlf)
For x = 0 to UBound(aPrinter)
  PrinterPath = aPrinter(x)
  objNet.RemovePrinterConnection PrinterPath, true
  'DisplayErrorInfo
Next
  'Wscript.Echo "Done. Removed " & x & " Printers"
end if
End Sub

'*************
'add printers
'*************

sub Mapprinters()
If fso.FileExists(LogonPath & "\Printers_add.csv") Then
  Set prnlist = fso.OpenTextFile(logonpath & "\Printers_add.csv", fsoForReading)
  aPrinter = Split(prnlist.Readall,vbcrlf)
For x = 0 to UBound(aPrinter)
  PrinterPath = aPrinter(x)
  objNet.AddWindowsPrinterConnection PrinterPath
Next
  'Wscript.Echo "Done. Mapped " & x & " Printers"

'******************************************************************************
'******************************************************************************
'**          Printer default selection box
'******************************************************************************
'******************************************************************************
Title = "Pick a Default Printer"
Text = "A new server as been put in place and I need you to choose your preferred printer. Listed below are the printers currently available to you.  Please enter the number that is next to the printer you prefer to have as your default printer.  The first number is 0 and goes through 11 or so. Please select a number accordingly" & vbCrLf & vbCrLf
Set oPrnEnum = objNet.EnumPrinterConnections
j = oPrnEnum.Count
For i = 0 To j - 1 Step 2
    Text = Text & (i/2) & vbTab
    Text = Text & oPrnEnum(i) & vbCrLF & oPrnEnum(i+1) & vbCrLf
    Next
tmp = InputBox(Text, "Company Default printer selector", 0)
If tmp = "" Then
    WScript.Echo "No user input, aborted"
    WScript.Quit
End If
tmp = CInt(tmp)
If (tmp < 0) Or (tmp > (j/2 - 1)) Then
    WScript.Echo "Wrong value, aborted"
    WScript.Quit
End If
printer = oPrnEnum(tmp*2 + 1)
objNet.SetDefaultPrinter printer
MsgBox "Thank you, your default printer has been successfully set to " & printer, _
        vbOKOnly + vbInformation, Title

End If
End Sub
Set objGroupList = Nothing
Set objUser = Nothing
Set objNet = Nothing      
Set fso = nothing
Set objShell = nothing
'msgbox "Logon Script Completed"

--------------------------------------------------------------------------

Here are the contents of the files it references:

------------------------------------------------------------------------

Printers_remove.csv

\\print\printer1
\\print\printer2
\\print\printer3

--------------------------------------------------------------------------

Printers_add.csv

\\print1\printer1
\\print1\printer2
\\print1\printer3

-----------------------------------------------------------------------

Any help or advice will be greatly appreciated.
SOLUTION
Avatar of Jay_Jay70
Jay_Jay70
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dmcoop

ASKER

I'll try that . . . however . . . I don't want to have to go through every users profile (or at least the ones at this location) to get this to work.  I'll do it as a troubleshooting step to see what happens.

I'm sorry I didn't make that clear.  I really want to get this thing to run out of a GPO.

Thanks!
Avatar of dmcoop

ASKER

Oh and for some background on this you can click on the link below:

https://www.experts-exchange.com/questions/21846990/Scripting-Print-Server-Printers-to-Domain-Computers.html

The above link takes you to the post I made to help get a good script file.  I like the script a lot . . . it does almost all that I want it to do and after I have all the old printers removed it will be perfect.  This may bring some context to what I am trying to do here.  We are rolling out a new print server and want to delete all the old printers and install all the new ones without having to touch each machine.

ahhh i see, thats a cool script!

when you set the script through the policy, and its applied, can you run a gpresult and make sure that the clients are actually picking up the policy
Avatar of Netman66
You don't have to go through everyone's account in AD.  Simply select all the accounts you want to use it (like you would multiple files), any common attributes can be changed all at once.

Avatar of dmcoop

ASKER

ok.  The gpresult shows that the policy is being applied to the test user . . . so . . . I have to assume something in the way the script is working is having a problem.

I'm gonna break the script down to a more basic script and see what happens.

I'll post back in a few.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
rewrite:

In your policy where are you assigning the script?  It should be under:

 USER CONFIGURATION//WINDOWS SETTINGS//SCRIPTS//LOGON

when you open the script logon/logoff properties, click show files button, it will open the script repository folder for the policy, paste your script in the folder.  Then click on the Add button and supply the name of the script you want to use =)
Avatar of dmcoop

ASKER

All right got it working through Group Policy Management.

I never could get it working through ADUC (user's profile).  

Anyway, here is what I did.

I used the gpresult tool to make sure the policy was being picked up by the PC.  It was.  I then created a small .vbs test script to make sure that the scripts would run and I dropped that into the USER CONFIGURATION//WINDOWS SETTINGS//SCRIPTS//LOGON portion the policy.  It did not work.  

So . . . I wondered if perhaps it is some type of replication problem . . . and found a decent script to force replication of all DCs.  After running that script I tried again it it worked.

Then I replaced the test script with the real one and tried it.  It did not work.  I did the force replication script again and then the logon script ran perfectly.

I think I must have another problem with replication or something.  I'm gonna start trouble shooting that now.

I'll be splitting the points between Jay_Jay70 and Mazaraat since their post helped me get to a point where I could trouble shoot and to confirm if I was setting things correctly.
Thanks, glad we could help.