Announcement

Collapse
No announcement yet.

Copy and Register DLL's

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Copy and Register DLL's

    So the idea of this was to copy a dll from my machine, to a list of computers in a text file in the same location and register it... there's a mix of XP and 2000 machines hence the check to see if system32 is in winnt or windows...

    but I have no idea if this works or not...

    This was the other week so I can't remember where I got the register code from but it was found in a google search...

    Anyone any idea if this works? =)


    Code:
    ' Copies DLL.dll to target machine (from list of computers in text file) and registers dll
    ' 
    
    
    ' Set Constants and list
    ' ----------------------------------------------------------------------
    
    On Error Resume Next
    
    ' Global constants and variables.
    Const FOR_READING = 1
    Const ForWriting = 2
    Const ForAppending = 8
    
    gstrCompFile = InputBox("Enter the Computer list from .txt file:" & VBNewLine & "Without file extension .txt", "RemRegDLL", "list")
    
    ' ---------------------------------------------------------------------
    ' Task
    ' ---------------------------------------------------------------------
    
    Sub Task()
    
    On Error Resume Next
    	strSource="DLL.dll"
    	Set Cshell = CreateObject("WScript.Shell")
    	set FSO = CreateObject("Scripting.FileSystemObject")
     
    	'check whether the system32 is WINNT or WINDOWS folder 
    	strSystem32XP = "\\" & gstrComputer & "\c$\windows\system32\"
    	if FSO.FolderExists (strSystem32XP) Then
    	   strsystem32 = "\\" & gstrComputer & "\c$\windows\system32\" 
    	else
    	    strSystem32 ="\\" & gstrComputer & "\c$\winnt\system32\" 
    	End if
    
    	FSO.CopyFile strSource,strSystem32,TRUE
    
    	Set objWMIService = GetObject ("winmgmts:\\" & gstrComputer & "\root\cimv2:Win32_Process")
    	strErrReturn = objWMIService.Create ("cmd.exe /c regsvr32.exe" & strSystem32 & "DLL.dll", Null, Null, intProcessID)
    	WScript.Echo "Register DLL.dll on " & gstrComputer & " returned with error: " & strErrReturn
    
    End Sub
    
    ' ---------------------------------------------------------------------
    ' Open .txt for computernames
    ' ---------------------------------------------------------------------
    
    ' Read computer names from gstrCompFile.
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(gstrCompFile & ".txt") Then
      Set objTextStream = objFSO.OpenTextFile(gstrCompFile & ".txt", FOR_READING)
    Else
      WScript.Echo "Input file " & gstrCompFile & ".txt" & " not found."
      WScript.Quit
    End If
    
    ' ---------------------------------------------------------------------
    ' Loop through list of computers and perform tasks on each.
    ' ---------------------------------------------------------------------
    
    On Error Resume Next
    
    Do Until objTextStream.AtEndOfStream
      gstrComputer = objTextStream.ReadLine
    
    	Task()
    
    Loop
    objTextStream.Close
    
    ' ---------------------------------------------------------------------
    This is my signature.

  • #2
    Re: Copy and Register DLL's

    To determine the systemdrive and systemroot (the windows folder) on a remote computer, read it from the registry on that computer.
    entry: [ HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRoot ]

    (or else, you could also search for the file 'win.ini' on any drive on the remote computer. This returns the systemdrive\systemfolder\win.ini. And next, in your case, replace 'win.ini' in the string with 'system32').

    Before the script tries to connect to the remote computer, it is recommended to perform a ping test -> to check whether the computer is connectable at the time. This extra function can save over_all process time.
    Q: Do you have Windows Script 5.6 installed in the Win2000 clients? http://cwashington.netreach.net/depo/view.asp?Index=739

    Don't forget to use the /s switch with regsvr32.exe !

    Write log (= create a new input file) with the names of the computers that where unable to connect. So you can re-run the script for only these computers.

    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Copy and Register DLL's

      Ah of course, I knew there'd be a better way to check for 2k/xp...

      hm, i ran this on a couple of machines and nothign poped up - any why to check if it is regsitered on them that you know of?

      and yes, ping test is a great idea too
      This is my signature.

      Comment


      • #4
        Re: Copy and Register DLL's

        Since you copied the DLL to the system32 folder (btw not a recommended folder if it ain't a Microsoft dll), it is not nessesary to specify the path of the dll-file in the regsvr.exe command line.
        Code:
        strErrReturn = objWMIService.Create ("Regsvr32.exe /s " & """DLL.dll""", Null, Null, intProcessID)
        Be sure the Regsvr32.exe switches are placed before the filename on the command line!
        http://technet.microsoft.com/nl-nl/l...85(en-us).aspx

        In your script you are using the administrativeshare\windows\system32 as the path to re-register the DLL. That is not correct, use the local path in the remote computer's perspective (c:\windows\system32) instead (also, in your example you didn't had a space between Regsvr32 and the path).
        So after you determine the %SystemRoot% on the remote computer and added \system32 to it, that is value for "strSystem32" you can use on the command-line:
        Code:
        strErrReturn = objWMIService.Create ("Regsvr32.exe /s """ & strSystem32 & "\DLL.dll""", Null, Null, intProcessID)

        Now, The path to copy the files to would then be:
        targetfolder = "\\" & gstrComputer & "\" & Replace(strSystem32, ":\","$\") & "\"

        To check whether the command was executed successfully, read the return values. And you can also check the corresponding registry subKey in HKEY_CLASSES_ROOT on one of the target computers.


        \Rems
        Last edited by Rems; 11th January 2008, 17:25.

        This posting is provided "AS IS" with no warranties, and confers no rights.

        __________________

        ** Remember to give credit where credit's due **
        and leave Reputation Points for meaningful posts

        Comment

        Working...
        X