VBS : Export the Network and printer registry key to another computer RRS feed

  • General discussion

  • hi

    i need to export the network and printer key to another computer

    my problem is i don't know what is the SID...the VBS script must save the keys According to the user connected.




    i found this function but i don't know how to intrage to my script:

    Private Shared Function GetNetworkPath(driveLetter As String) As String
           Using key = Registry.CurrentUser.OpenSubKey("Network\" & driveLetter)
                 If key IsNot Nothing Then
                         Return DirectCast(key.GetValue("RemotePath"), String)
                 End If
              Return Nothing
           End Using
    End Function

    i need something like this...

    any Help please?

    • Changed type Bill_Stewart Friday, December 30, 2016 9:21 PM
    Monday, November 21, 2016 10:50 AM

All replies

  • Hi

    I need to import registry key from a remote computer.

    my problem is, when a user change his computer he must recovery his printers and his mapping drives from his old computer.

    To do that, i need the registry keys from the old computer.

    i already have an HTA GUI to ask user to put his old computer name but i don't know how use it again.

    this is a part of my vb script:

    function BrowseForFolderDistant()
    	Dim Path, oFolder, oShell, PathDesktop
    	oFolder = ""
    	set oShell = CreateObject("Shell.Application")
        if Input_Desktop.value = "" then 
        end if
        PathDesktop = "\\" + Input_Desktop.value + "\c$" 
    	set oFolder = oShell.BrowseForFolder(0, "Choose a Folder", 0, PathDesktop)
    	on error resume next
    	Path = oFolder.ParentFolder.ParseName(oFolder.Title).Path
    	if Err.Number = 0 then
    		if (Right(Path, 1) <> "\\") then
    			Path = Path & "\\"
    		end if
    		Path = ""
    	end if
    	Set oFolder = Nothing
    	Set oShell = Nothing
    	BrowseForFolderDistant = Path
    end function

    how can i create another function to integrate this computer name?

    IF you have another solution to recovery the network printers and the network drive i take. :-).

    • Edited by saidou92 Thursday, November 17, 2016 8:28 AM
    • Merged by Bill_Stewart Monday, November 21, 2016 3:11 PM Duplicate
    Thursday, November 17, 2016 8:26 AM
  • A user cannot read a remote computer registry.  A user cannot remotely access the contents of a remote computer except for shares that the user has permissions on.

    You can use migration tools to extract user configuration on one computer and transfer to a other.

    See MDT: https://technet.microsoft.com/en-us/windows/dn475741.aspx


    Thursday, November 17, 2016 5:09 PM
  • There is a tool for moving users called USMT.


    The code you posted in not script.  It is VB.Net

    In PowerShell you can do:


    These produce the same result as the code posted.


    Monday, November 21, 2016 11:02 AM
  • HI

    I am trying to exporte reg KEY with vbscript.

    when i launch  the scritp i have an error message " 800A01C3 this object is not a collection ".

    that is my export function:

    Function ExportPrinterRegistryKey()

    Dim wshShell, strUsername, strDomain, arrSubKeys, arrValueNames, arrValueTypes, SZValue, EXPAND_SZValue, BINARYValue, DWORDValue, MULTI_SZValue
    Dim getSIDLocal,   objWMIServiceLocal,   objAccountLocal,   oRegDLocal,  strKeyPathLocal,   strComputerLocal,   strKeyPathChildLocal
    Dim getSIDDistant, objWMIServiceDistant, objAccountDistant, oRegDistant, strKeyPathDistant, strComputerDistant, strKeyPathChildDistant

    const REG_SZ = 1
    const REG_EXPAND_SZ = 2
    const REG_BINARY = 3
    const REG_DWORD = 4
    const REG_MULTI_SZ = 7
    Const HKEY_USERS   = &H80000003

    Set wshShell = CreateObject("WScript.Shell")
    strUsername = wshShell.ExpandEnvironmentStrings("%USERNAME%")
    strDomain = wshShell.ExpandEnvironmentStrings("%USERDOMAIN%")

    strComputerDistant = Input_Desktop.value

    Set objWMIServiceDistant = GetObject("winmgmts:\\" & strComputerDistant & "\root\cimv2")
    Set objAccountDistant = objWMIServiceDistant.Get("Win32_UserAccount.Name='" & strUsername & "',Domain='" & strDomain & "'")
    getSIDDistant = objAccountDistant.SID
    Set oRegDistant=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerDistant & "\root\default:StdRegProv")
    strKeyPathDistant =  Trim(getSIDDistant) & "\Printers\Connections\"

    strComputerLocal = "."
    Set objWMIServiceLocal = GetObject("winmgmts:\\" & strComputerLocal & "\root\cimv2")
    Set objAccountLocal = objWMIServiceLocal.Get("Win32_UserAccount.Name='" & strUsername & "',Domain='" & strDomain & "'")
    getSIDLocal = objAccountLocal.SID
    Set oRegLocal=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputerLocal & "\root\default:StdRegProv")
    strKeyPathLocal =  Trim(getSIDLocal) & "\Printers\Connections\"

    oRegDistant.EnumKey HKEY_USERS, strKeyPathDistant, arrSubKeys

    For Each subkey In arrSubKeys
        strKeyPathChildDistant  = strKeyPathDistant & subkey 
        strKeyPathChildLocal  = strKeyPathLocal  & subkey 

        Return = oRegLocal.CreateKey(HKEY_USERS, strKeyPathChildLocal)

        If (Return = 0) And (Err.Number = 0) Then
            oRegDistant.EnumValues HKEY_USERS, strKeyPathChildDistant, arrValueNames, arrValueTypes
            For I=0 To UBound(arrValueNames)           
                Return = 0
                Select Case arrValueTypes(I)
                    Case REG_SZ
                        Return = oRegDistant.GetStringValue       (HKEY_USERS, strKeyPathChildDistant, arrValueNames(I), SZValue )  
                        Return = oRegLocal.SetStringValue( HKEY_USERS, strKeyPathChildLocal, arrValueNames(I), SZValue)               
                    Case REG_EXPAND_SZ    
                        oRegDistant.GetExpandedStringValue          HKEY_USERS, strKeyPathChildDistant,arrValueNames(I),EXPAND_SZValue  
                        Return = oRegLocal.SetExpandedStringValue( HKEY_USERS, strKeyPathChildLocal, arrValueNames(I), EXPAND_SZValue)
                    Case REG_BINARY
                        oRegDistant.GetBinaryValue                  HKEY_USERS, strKeyPathChildDistant, arrValueNames(I), BINARYValue
                        Return = oRegLocal.SetBinaryValue(    HKEY_USERS, strKeyPathChildLocal, arrValueNames(I), BINARYValue) 
                    Case REG_DWORD                  
                        oRegDistant.GetDWORDValue                   HKEY_USERS, strKeyPathChildDistant, arrValueNames(I), DWORDValue                   
                        oRegLocal.SetDWORDValue               HKEY_USERS, strKeyPathChildLocal, arrValueNames(I), DWORDValue      
                    Case REG_MULTI_SZ
                        oRegDistant.GetMultiStringValue             HKEY_USERS, strKeyPathChildDistant, arrValueNames(I), MULTI_SZValue
                        oRegLocal.SetMultiStringValue              HKEY_USERS, strKeyPathChildLocal, arrValueNames(I), MULTI_SZValue
                End Select


        End If


    End Function

    Can you help me please?

    • Edited by saidou92 Wednesday, November 23, 2016 8:34 AM
    • Merged by Bill_Stewart Wednesday, November 23, 2016 3:15 PM Duplicate
    Wednesday, November 23, 2016 8:31 AM
  • i know USMT...I would like to use it but i can't.

    i am working for a company and they want i create a HTA application to recovery the users data and parameters.

    Wednesday, November 23, 2016 8:40 AM
  • i know USMT...I would like to use it but i can't.

    i am working for a company and they want i create a HTA application to recovery the users data and parameters.

    Then they should hire a consultant who knows how to write old, obsolete code and be willing to pay a lot of money to re-invent the wheel.

    C'mon.  No real company would ever require such a ridiculous thing in the 21st century.

    If you really must do this you will have to learn how to use HTML and VB. Here is where to start: http://www.w3schools.com/

    Unfortunately Microsoft has removed most content about HTAs from its site as it is obsolete.  If you search you might still find some old sites that will teach you how to do this.

    Modern systems cannot be managed with an HTA.  You can do many things but all newer systems do not have support for VBScript and HTAs.

    USMT, The built in migration wizard and PowerShell have been the standards since Windows XP.


    Wednesday, November 23, 2016 12:17 PM
  • You cannot remotely access a users hive if the user is not logged in.

    To capture user data give user a batch file with "REG EXPORT".



    Wednesday, November 23, 2016 2:20 PM
  • OK, so now we're trying a fishing expedition.

    The following blog post will be helpful:

    If you didn't like the answer, asking the same question again is unlikely to help

    -- Bill Stewart [Bill_Stewart]

    Wednesday, November 23, 2016 3:16 PM
  • the user will be connected on the both computer.
    Thursday, November 24, 2016 8:14 AM
  • Thursday, November 24, 2016 7:47 PM