none
Script not taking effect on Windows 7 RRS feed

  • Question

  • I have this script running and had it working in Windows 10 machine but not in Wins7, which is odd because the script was created to run on Windows 7. What I did is I attached this policy under GPO > User Config > Policies > Windows Settings > Scripts.. Could someone shine a light on me?

    I also tried to run this script manually on a windows 7 machine but no changes is taking effect.

    The name of the script is PrinterMigration.vbs and it was posted by Draguaine


    ' put in the server names here (keep the quotes!)  
    MovePrinters "Old Server""New Server"  
     
     
    ' *********************************************  
    ' Move printers to new server  
    ' *********************************************  
    Sub MovePrinters(OldServer, NewServer)  
    ' Loops through all network printers and moves all printers  
    ' on "OldServer" to the same printername on "NewServer".  
    dim WshNetwork, oPrinters, i, PrinterPath, DefaultPrinter, PrinterList  
     
    Set WshNetwork = WScript.CreateObject("WScript.Network")  
    Set PrinterList = CreateObject("Scripting.Dictionary")  
     
    ' Get the default printer before we start deleting:  
    DefaultPrinter = GetDefaultPrinter  
     
    ' Get a list of printers to work with:  
    ' (We cannot modify the collection while looping through it)  
    Set oPrinters = WshNetwork.EnumPrinterConnections  
        For i = 1 to oPrinters.Count Step 2  
        PrinterList.Add oPrinters.Item(i), "x"   
        Next ' i  
     
    ' Loop through the printer list and migrate mathching ones:  
    For Each PrinterPath In PrinterList.Keys  
     
        If StrComp(ServerName(PrinterPath), OldServer, 1) = 0 Then  
            WshNetwork.RemovePrinterConnection PrinterPath, TrueTrue  
            On Error Resume next  
            WshNetwork.AddWindowsPrinterConnection "\\" & NewServer & "\" & _  
                ShareName(PrinterPath)  
                If Err.Number = 0 Then  
                    Set objFile = wscript.CreateObject("Scripting.FileSystemObject")  
                    If Not objFile.FolderExists("c:\printers_remapped"Then  
                    objFile.CreateFolder "c:\printers_remapped"  
                    objFile.Close  
                    End If  
                End If     
                'If Err.Number = -2147023095 Then  
                ' MsgBox "The printer """ & ShareName(PrinterPath) & _  
                ' """ does not exist on server """ & NewServer & """." & vbCrLf & _  
                ' "The printer has been removed.", vbOKonly + vbExclamation, _  
                ' "Missing printer"  
                'End If  
            On Error goto 0  
        End If  
    Next  
     
    'Set the default printer:  
    If ServerName(DefaultPrinter) = OldServer Then  
        On Error Resume Next  
        WshNetwork.SetDefaultPrinter "\\" & NewServer & "\" & _  
        ShareName(DefaultPrinter)  
        'If Err.Number = -2147352567 Then  
        'MsgBox "Your default printer did not exist, and has been deleted.", _  
        ' vbOKonly + vbInformation, "Invalid default printer"  
        'End If  
        On Error goto 0  
    End If  
    End Sub ' MovePrinters  
     
     
    Function GetDefaultPrinter()  
    ' Returns the UNC path to the current default printer  
    Dim oShell, sRegVal, sDefault  
    Set oShell = CreateObject("WScript.Shell")  
    sRegVal = _  
        "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"  
    sDefault = ""  
    On Error Resume Next  
    sDefault = oShell.RegRead(sRegVal)  
    sDefault = Left(sDefault ,InStr(sDefault, ",") - 1)  
    On Error Goto 0  
    GetDefaultPrinter = sDefault  
    End Function  
     
     
    Function ServerName(sPrinterPath)  
    Dim aPrinterPath  
    ServerName = ""  
    If Left(sPrinterPath, 2) = "\\" Then  
        aPrinterPath = Split(sPrinterPath, "\")  
        ServerName = aPrinterPath(2)  
    End If  
    End Function  
     
     
    Function ShareName(sPrinterPath)  
    Dim aPrinterPath  
    ShareName = ""  
        If Left(sPrinterPath, 2) = "\\" Then  
        aPrinterPath = Split(sPrinterPath, "\")  
        ShareName = aPrinterPath(3)  
    End If  
    End Function  
     
    discardScript()     
         
        Function discardScript() 
            Set objFSO = CreateObject("Scripting.FileSystemObject") 
            strScript = Wscript.ScriptFullName 
            objFSO.DeleteFile(strScript) 
        End Function 
     
     
    '--------------------8<----------------------  



    Friday, February 7, 2020 7:10 PM

Answers

All replies

  • What?  What policy?  What script?

    YOU seem to have forgotten to post any information other than that some script failed because you changed some policy.


    \_(ツ)_/

    Friday, February 7, 2020 8:07 PM
  • We cannot fix scripts that you have found on the Internet.

    Please ask the author of the script for help.

    Many old VBS scripts will no longer work in Windows due to changes in security.  We cannot guess at your issue or guess at the script.  Only the author of the script is likely to be of any help.

    This forum is not for end users and not an MS support forum.  You would do best by consulting a trained technician to help you.


    \_(ツ)_/

    Friday, February 7, 2020 11:20 PM
  • I must have forgotten. This script is called printermigration.vbs The only changes I made is the name of the old server to the new server and I removed the discard function. Like i mentioned that this script is working manually or through a GPO but it only works on Win 10 machines but not on Win 7. 

    Thanks! in advance

    ' put in the server names here (keep the quotes!)  
    MovePrinters "Old Server""New Server"  
     
     
    ' *********************************************  
    ' Move printers to new server  
    ' *********************************************  
    Sub MovePrinters(OldServer, NewServer)  
    ' Loops through all network printers and moves all printers  
    ' on "OldServer" to the same printername on "NewServer".  
    dim WshNetwork, oPrinters, i, PrinterPath, DefaultPrinter, PrinterList  
     
    Set WshNetwork = WScript.CreateObject("WScript.Network")  
    Set PrinterList = CreateObject("Scripting.Dictionary")  
     
    ' Get the default printer before we start deleting:  
    DefaultPrinter = GetDefaultPrinter  
     
    ' Get a list of printers to work with:  
    ' (We cannot modify the collection while looping through it)  
    Set oPrinters = WshNetwork.EnumPrinterConnections  
        For i = 1 to oPrinters.Count Step 2  
        PrinterList.Add oPrinters.Item(i), "x"   
        Next ' i  
     
    ' Loop through the printer list and migrate mathching ones:  
    For Each PrinterPath In PrinterList.Keys  
     
        If StrComp(ServerName(PrinterPath), OldServer, 1) = 0 Then  
            WshNetwork.RemovePrinterConnection PrinterPath, TrueTrue  
            On Error Resume next  
            WshNetwork.AddWindowsPrinterConnection "\\" & NewServer & "\" & _  
                ShareName(PrinterPath)  
                If Err.Number = 0 Then  
                    Set objFile = wscript.CreateObject("Scripting.FileSystemObject")  
                    If Not objFile.FolderExists("c:\printers_remapped"Then  
                    objFile.CreateFolder "c:\printers_remapped"  
                    objFile.Close  
                    End If  
                End If     
                'If Err.Number = -2147023095 Then  
                ' MsgBox "The printer """ & ShareName(PrinterPath) & _  
                ' """ does not exist on server """ & NewServer & """." & vbCrLf & _  
                ' "The printer has been removed.", vbOKonly + vbExclamation, _  
                ' "Missing printer"  
                'End If  
            On Error goto 0  
        End If  
    Next  
     
    'Set the default printer:  
    If ServerName(DefaultPrinter) = OldServer Then  
        On Error Resume Next  
        WshNetwork.SetDefaultPrinter "\\" & NewServer & "\" & _  
        ShareName(DefaultPrinter)  
        'If Err.Number = -2147352567 Then  
        'MsgBox "Your default printer did not exist, and has been deleted.", _  
        ' vbOKonly + vbInformation, "Invalid default printer"  
        'End If  
        On Error goto 0  
    End If  
    End Sub ' MovePrinters  
     
     
    Function GetDefaultPrinter()  
    ' Returns the UNC path to the current default printer  
    Dim oShell, sRegVal, sDefault  
    Set oShell = CreateObject("WScript.Shell")  
    sRegVal = _  
        "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows\Device"  
    sDefault = ""  
    On Error Resume Next  
    sDefault = oShell.RegRead(sRegVal)  
    sDefault = Left(sDefault ,InStr(sDefault, ",") - 1)  
    On Error Goto 0  
    GetDefaultPrinter = sDefault  
    End Function  
     
     
    Function ServerName(sPrinterPath)  
    Dim aPrinterPath  
    ServerName = ""  
    If Left(sPrinterPath, 2) = "\\" Then  
        aPrinterPath = Split(sPrinterPath, "\")  
        ServerName = aPrinterPath(2)  
    End If  
    End Function  
     
     
    Function ShareName(sPrinterPath)  
    Dim aPrinterPath  
    ShareName = ""  
        If Left(sPrinterPath, 2) = "\\" Then  
        aPrinterPath = Split(sPrinterPath, "\")  
        ShareName = aPrinterPath(3)  
    End If  
    End Function  
    
    '--------------------8<----------------------  

    Friday, February 7, 2020 11:21 PM
  • I maybe new at this field and new in creating GPO policy but I can understand a bit of it's process. The script that I got it from is on this website. I did asked the contributor, hopefully he respond. 
    Friday, February 7, 2020 11:30 PM
  • There is no way to understand what you are asking.  You have not posted any useful information.  We will move this topic to the off-topics forum since this is not the correct forum for an end user support request.


    \_(ツ)_/

    Friday, February 7, 2020 11:36 PM
  • For the future please read all of the following links carefully:

    Please carefully review the following links to set your expectation for posting in technical forums.


    \_(ツ)_/

    • Marked as answer by Jed the ITguy Friday, February 7, 2020 11:41 PM
    Friday, February 7, 2020 11:37 PM