+ Post New Thread
Page 3 of 3 FirstFirst 123
Results 31 to 39 of 39
Scripts Thread, Need help in sorting these scripts out and possible better solutions. in Coding and Web Development; Here is the script that I have completed, so far. I still need to add the user name change. Could ...
  1. #31

    Join Date
    Jul 2011
    Location
    USA
    Posts
    27
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Here is the script that I have completed, so far. I still need to add the user name change. Could someone check it out and make any changes that it might need and see if it flows from one task to the other.

    Code:
    On Error Resume Next
    
    Dim objWShell
    
    Set objWShell = WScript.CreateObject("WScript.Shell")
    
    getVersionNumber = objWShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
    getOsType = objWShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
    getProductName = objWShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
    ComputerName = "WinIDS"
    
    'Tests for x86 processor architecture and eXits if not.
    If getOsType = "x86" Then
    
    'Tests for Windows Windows 7 (6.1) and continues if not.
    	If getVersionNumber = "6.1" Then
    
    'Sets registry to disable ELUA, Show Hidden files and folders, and display file extensions.
          objWShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA", "0", "REG_DWORD"
          objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", "1", "REG_DWORD"
          objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt", "0", "REG_DWORD"
    
    'Changes the computer name.
          Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
          Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
          objComputer = "."
          For Each objComputer In colComputers
             err = objComputer.Rename(ComputerName)
          Next
    	  If err <> 0 Then
             Msgbox "There was an error renaming the machine. Please restart, and try again."
          Else
          Set objWMIService = Nothing
          Set colComputera = Nothing
    
    'Tests for Windows XP (5.1) or Windows Server 2003 (5.2) and eXits script if not.
    	ElseIf getVersionNumber = "5.2" Or "5.1" Then
    
    'Sets registry to Show Hidden files and folders, and display file extensions.
          objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", "1", "REG_DWORD"
          objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt", "0", "REG_DWORD"
    
    'Changes the computer name.
          objWShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName", computerName
          objWShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\ParameterS\NV Hostname", computerName
    	Else
     
    	  Msgbox "The OS Product Name is " & getProductName & ", and is not supported!" & VbCrLf & VbCrLf & "Supported Product Names: XP SP3, Server 2003 SP2, and Windows 7",vbokonly,"Detecting Product Name..."
          WScript.Quit
       End If
    Else
       Msgbox "The detected processor architecture is: " & getOsType & VbCrLf & VbCrLf & "The WinIDS install only supports 32bit architecture at this time!",vbokonly,"Detecting Processor Architecture..."
       WScript.Quit
    End If
    
    'Tests for username and creates or alters user account based on exists or does not exist. 
    'To be completed
    
    'This finally does a shutdown to apply changes made.
    objWShell.Run "shutdown /r /t 10 /f /d P:4:2" 'Restarts OS in 10 seconds to apply changes.
    
    Set objWShell = Nothing

  2. #32

    Join Date
    Jul 2011
    Location
    USA
    Posts
    27
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    I'm having a small problem with this sub routine:

    The getVersionNumber is having a problem. If the getVersionNumber equals either 5.1, 5.2, 0r 6.1 then it's supposed to jump over and continue. However it executes the next line and quits.

    Code:
    getOsType = "x86"
    getVersionNumber = "6.1"
    
    If getOsType <> "x86" Then
    	Msgbox "The detected processor architecture is: " & getOsType & VbCrLf & VbCrLf & "The WinIDS install only supports 32bit architecture at this time!",vbokonly,"Detecting Processor Architecture..."
    	WScript.Quit
    	ElseIf getVersionNumber <> "5.1" or getVersionNumber <> "5.2" or getVersionNumber <> "6.1" Then
    	Msgbox "The OS Product Name is " & getProductName & ", and is not supported!" & VbCrLf & VbCrLf & "Supported Product Names: XP SP3, Server 2003 SP2, and Windows 7",vbokonly,"Detecting Product Name..."
    	WScript.Quit
    	End If
    Solved:

    Code:
    If getOsType <> "x86" Then
    	Msgbox "The detected processor architecture is: " & getOsType & VbCrLf & VbCrLf & "The WinIDS install only supports 32bit architecture at this time!",vbokonly,"Detecting Processor Architecture..."
    	WScript.Quit
    	ElseIf getVersionNumber <> "5.1" and getVersionNumber <> "5.2" and getVersionNumber <> "6.1" Then
    	Msgbox "The OS Product Name is " & getProductName & ", and is not supported!" & VbCrLf & VbCrLf & "Supported Product Names: XP SP3, Server 2003 SP2, and Windows 7",vbokonly,"Detecting Product Name..."
    	WScript.Quit
    	End If
    Unless there is a better way to do this?
    Last edited by mesteele101; 26th August 2011 at 01:26 PM.

  3. #33

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,216
    Thank Post
    2,767
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    the wscript.quit is what makes it exit so depends where you have these placed as to when it quits out of the script before continueing, I have used select case in the below code chunk instead of all the nested if, else code blocks

    Code:
    On Error Resume Next
    
    Dim objWShell
    
    Set objWShell = WScript.CreateObject("WScript.Shell")
    
    getVersionNumber = objWShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
    getOsType = objWShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
    getProductName = objWShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
    ComputerName = "WinIDS"
    
    'Tests for x86 processor architecture and eXits if not.
    If getOsType = "x86" Then
    
    'Tests for Windows Windows 7 (6.1) and continues if not.
        
        Select Case getVersionNumber
    
            Case "6.1":
    
            'Sets registry to disable ELUA, Show Hidden files and folders, and display file extensions.
                  objWShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA", "0", "REG_DWORD"
                  objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", "1", "REG_DWORD"
                  objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt", "0", "REG_DWORD"
    
            'Changes the computer name.
                  Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
                  Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
                 objComputer = "."
                  For Each objComputer In colComputers
                     err = objComputer.Rename(ComputerName)
                  Next
                  If err <> 0 Then
                         Msgbox "There was an error renaming the machine. Please restart, and try again."
                      Else
                          Set objWMIService = Nothing
                          Set colComputera = Nothing
                End If
    
                'Tests for Windows XP (5.1) or Windows Server 2003 (5.2) and eXits script if not.
    
            Case "5.2" Or "5.1":
    
            'Sets registry to Show Hidden files and folders, and display file extensions.
                  objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", "1", "REG_DWORD"
                  objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt", "0", "REG_DWORD"
    
            'Changes the computer name.
                  objWShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName", computerName
                  objWShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\ParameterS\NV Hostname", computerName
    
            Case Else:
    
            Msgbox "The OS Product Name is " & getProductName & _
             ", and is not supported!" & VbCrLf & VbCrLf & _ 
            "Supported Product Names: XP SP3, Server 2003 SP2, and Windows 7",vbokonly,"Detecting Product Name..."
            Wscript.Quit
    
            End Select
    
            Else
    
       Msgbox "The detected processor architecture is: " & getOsType & VbCrLf & VbCrLf & _
      "The WinIDS install only supports 32bit architecture at this time!",vbokonly,"Detecting Processor Architecture..."
       WScript.Quit
    End If
    
    'Tests for username and creates or alters user account based on exists or does not exist. 
    'To be completed
    
    'This finally does a shutdown to apply changes made.
    objWShell.Run "shutdown /r /t 10 /f /d P:4:2" 'Restarts OS in 10 seconds to apply changes.
    
    Set objWShell = Nothing

  4. #34

    Join Date
    Jul 2011
    Location
    USA
    Posts
    27
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Code:
    On Error Resume Next
    
    Dim objWShell
    
    Set objWShell = WScript.CreateObject("WScript.Shell")
    
    getVersionNumber = objWShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
    getOsType = objWShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
    getProductName = objWShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
    ComputerName = "WinIDS"
    
    If getOsType = "x86" Then
    
        Select Case getVersionNumber
    
            Case "6.1":
    
    	Executes this code if it's 6.1, and proceeds to the Continue On...
    
            Case "5.2" Or "5.1":
    
    
    	Executes this code if it's 5.1 or 5.2, and proceeds to the Continue On...
    
    
            Case Else:
    
    	Ececutes this code if it's not 6.1, 5.1, or 5.2
    
            End Select
    
            Else
    
    Executes this code if it's Not x86
    
    End If
    
    Continue On...

    I Was thinking that placing the checks first dumping the user out of the script, which the above is basically doing but inserting the executable code in the middle of the checks.

    Code:
    If getOsType <> "x86" Then
    	Msgbox "The detected processor architecture is: " & getOsType & VbCrLf & VbCrLf & "The WinIDS install only supports 32bit architecture at this time!",vbokonly,"Detecting Processor Architecture..."
    	WScript.Quit
    	ElseIf getVersionNumber <> "5.1" and getVersionNumber <> "5.2" and getVersionNumber <> "6.1" Then
    	Msgbox "The OS Product Name is " & getProductName & ", and is not supported!" & VbCrLf & VbCrLf & "Supported Product Names: XP SP3, Server 2003 SP2, and Windows 7",vbokonly,"Detecting Product Name..."
    	WScript.Quit
    	End If
    It just looks like there should be a better way then my example.

    I have another problem that requires setting policies for the Administrators group. Do you know how to do this from the script?

    Code:
    objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", "1", "REG_DWORD"
    objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt", "0", "REG_DWORD"

  5. #35

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,216
    Thank Post
    2,767
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    Modified so it uses just select case statements, one for the getOsType and one for the check ref cpu type being x86 and nothing else.

    I don't understand what you are trying to do or what needs doing ref your last comment - see below, will explain further after the code chunk

    Code:
    On Error Resume Next
    
    Dim objWShell
    
    
    Set objWShell = WScript.CreateObject("WScript.Shell")
    
    
    getVersionNumber = objWShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
    getOsType = objWShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
    getProductName = objWShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
    ComputerName = "WinIDS"
    'Tests for Windows Windows 7 (6.1) and continues if not.
    
    
    Select Case getOsType
    
    
    Case "x86":
        
        Select Case getVersionNumber
    
    
            Case "6.1":
    
    
            'Sets registry to disable ELUA, Show Hidden files and folders, and display file extensions.
                  objWShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA", "0", "REG_DWORD"
                  objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", "1", "REG_DWORD"
                  objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt", "0", "REG_DWORD"
    
    
            'Changes the computer name.
                  Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
                  Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
                 objComputer = "."
                  For Each objComputer In colComputers
                     err = objComputer.Rename(ComputerName)
                  Next
                  If err <> 0 Then
                         Msgbox "There was an error renaming the machine. Please restart, and try again."
                      Else
                          Set objWMIService = Nothing
                          Set colComputera = Nothing
                End If
    
    
                'Tests for Windows XP (5.1) or Windows Server 2003 (5.2) and eXits script if not.
    
    
            Case "5.2" Or "5.1":
    
    
            'Sets registry to Show Hidden files and folders, and display file extensions.
                  objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", "1", "REG_DWORD"
                  objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt", "0", "REG_DWORD"
    
    
            'Changes the computer name.
                  objWShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName", computerName
                  objWShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\ParameterS\NV Hostname", computerName
    
    
            Case Else:
    
    
            Msgbox "The OS Product Name is " & getProductName & _
             ", and is not supported!" & VbCrLf & VbCrLf & _ 
            "Supported Product Names: XP SP3, Server 2003 SP2, and Windows 7",vbokonly,"Detecting Product Name..."
            Wscript.Quit
    
    
            End Select
    Case Else:
    
    
    Msgbox "The detected processor architecture is: " & getOsType & VbCrLf & VbCrLf & _
      "The WinIDS install only supports 32bit architecture at this time!",vbokonly,"Detecting Processor Architecture..."
       WScript.Quit
    End Select
    
    
    'Tests for username and creates or alters user account based on exists or does not exist. 
    'To be completed
    
    
    'This finally does a shutdown to apply changes made.
    objWShell.Run "shutdown /r /t 10 /f /d P:4:2" 'Restarts OS in 10 seconds to apply changes.
    
    
    Set objWShell = Nothing
    Code:
    objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", "1", "REG_DWORD"objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt", "0", "REG_DWORD"
    Are you saying that you are setting the reg keys and they are not taking effect straight away or what exactly in regards to the 2 above registry keys ?

  6. #36

    Join Date
    Jul 2011
    Location
    USA
    Posts
    27
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    What is happening is that if the user is logged in as user x and and runs the script, it's creating the User Operator, and the script is setting those two registry settings for user x and not Operator.

    The UAC registry setting is being set because it's HKLM whereas the other two are using HKCU.

    The solution is to set an Administrators group policy for those two items. Possibly, I was thinking, the script could create the user account and reboot telling the user to log back on with the new Operator credentials and run the script again. I would need to figure out how to bypass the routine that creates the user account, seeing it's already done this. The three things that needs checked ar; Username, Password, and Administrator access. If all three of those are met then it could bypass the routine that creates the user account. This is a really ugly way to do it.

  7. #37

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,216
    Thank Post
    2,767
    Thanked 935 Times in 875 Posts
    Rep Power
    343
    Quote Originally Posted by mesteele101 View Post
    What is happening is that if the user is logged in as user x and and runs the script, it's creating the User Operator, and the script is setting those two registry settings for user x and not Operator.

    The UAC registry setting is being set because it's HKLM whereas the other two are using HKCU.

    The solution is to set an Administrators group policy for those two items. Possibly, I was thinking, the script could create the user account and reboot telling the user to log back on with the new Operator credentials and run the script again. I would need to figure out how to bypass the routine that creates the user account, seeing it's already done this. The three things that needs checked ar; Username, Password, and Administrator access. If all three of those are met then it could bypass the routine that creates the user account. This is a really ugly way to do it.
    username and admin access ( local admin I presume you mean ) I can do, but what do you mean by password ?

    Also I need you to show me which chunks of code need to run if these 3 conditions are met and which chunks of code I need to run if these conditions are not met ??

  8. #38

    Join Date
    Jul 2011
    Location
    USA
    Posts
    27
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    This is all local. There are two sections of this part of the script.

    Section one: The user Operator does not exist it

    1) Creates the Operator account
    2) Sets the password
    3) Sets the password to never expire
    4) Add the user Operator to the Administrators group
    5) Jumps over the next section

    If the user Operator already exists then

    1) It sets the password
    2) Sets the password to never expire
    3) It checks see if the user Operator belongs to the Administrators group, and jumps over if it does

    With Item 3 above there may be a better way to do it? If the usrer operator already belongs to the Administrators group the script gets an error, so I added a check. There is most likely a better way to do this?

    The script below works as is. However if it needs to create the Operator user, the registry settings cannot be set for Operator because you can only set those using the HKCU registry.

    I'm not real sure how to do this. I was thinking to set those in the Administrators group policies. If the Operator account does not exisit then have it do section 1 and then ave a msgbox popup telling the installer that after the reboot they will need to log back using the newly created Operator account, and run the script again. After logging back in using the Operator account the script would check to see if the current user name, password, and group assignment was set correctly, and then bypass that part of the script.


    The installer would only need to reboot if section one was executed. With section two the user Operator already exists and the script could continue on.

    Code:
    On Error Resume Next
    
    Dim objWShell
    
    Set objWShell = WScript.CreateObject("WScript.Shell")
    
    getVersionNumber = objWShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
    getOsType = objWShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
    getProductName = objWShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
    ComputerName = "WinIDS"
    accUserName = "Operator"
    accUserPass = "p@ss"
    
    'This tests for x86 processor architecture, and exits if not. Install is not 64bit capable.
    If getOsType <> "x86" Then
    	Msgbox "The detected processor architecture is: " & getOsType & VbCrLf & VbCrLf & "The WinIDS install only supports 32bit architecture at this time!",vbokonly,"Detecting Processor Architecture..."
    	WScript.Quit
    	ElseIf getVersionNumber <> "5.1" and getVersionNumber <> "5.2" and getVersionNumber <> "6.1" Then
    	Msgbox "The OS Product Name is " & getProductName & ", and is not supported!" & VbCrLf & VbCrLf & "Supported Product Names: XP SP3, Server 2003 SP2, and Windows 7",vbokonly,"Detecting Product Name..."
    	WScript.Quit
    	End If
    
    QueryForUser(accUserName)
    	'This creates the new username if it doesn't exist
    	Set objNetwork = CreateObject("Wscript.Network")
    		strComputer = objNetwork.ComputerName
    	Set objComputer = GetObject("WinNT://" &strComputer)
    	Set colAccounts = GetObject("WinNT://" & strComputer & "")
    	Set objUser = colAccounts.Create("user", accUserName)
    		objUser.SetPassword accUserPass
    		objUser.Put "UserFlags", 65600 '
    		objUser.SetInfo	
    
    		'This adds user to Administrators group
    	Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
    	Set objUser = GetObject("WinNT://" & strComputer & "/" & accUserName & ",user")
    		objGroup.Add(objUser.ADsPath)
    
    	'This changes the password if the user exists
    	Sub QueryForUser(strUserName)
    	Set objlocal = GetObject("WinNT://.")
    		objlocal.Filter = Array("user")
    	For Each User In objlocal
    		If lcase(User.Name) = lcase(strUserName) Then
    				strComputer = "."
    	Set objUser = GetObject("WinNT://" & strComputer & "/" & accUserName & ", user")
    				objUser.SetPassword accUserPass
    				objUser.SetInfo
    
    			'This checks to see if the user needs added to the Administrators Group
        Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
    				For Each objUser in objGroup.Members
    					If objUser.Name = accUserName Then
    						Else
    							Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
    							Set objUser = GetObject("WinNT://" & strComputer & "/" & accUserName & ",user")
    								objGroup.Add(objUser.ADsPath)
    						End If
    				Next
    End If   
    Next
    
    End Sub
    When the scripts gets to the end the user has to be Operator in order for the registry settings to be set.

    I didn't incorporate the changes you mentioned so you could see the original script. There are other parts to the script but this part needs to work and the other parts will fall right in.

    TIA...

    PS I might mot be able to get right back becuse we are under a hurricane watch and might have no power.
    Last edited by mesteele101; 27th August 2011 at 12:44 AM.

  9. #39

    Join Date
    Jul 2011
    Location
    USA
    Posts
    27
    Thank Post
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Here is the complete script. I have't added the 'case' to it. I'm having a couple of problems:

    1) It seems to be looping through some of the routines.

    2) If the user has to be created then the HKCU registry settings that are being created won't apply for the newly created user

    There might be better ways to code some of the routines All I can do with this type of code is hack at it.
    Code:
    On Error Resume Next
    
    Dim objWShell
    
    Set objWShell = WScript.CreateObject("WScript.Shell")
    
    getVersionNumber = objWShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
    getOsType = objWShell.RegRead("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE")
    getProductName = objWShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
    
    ComputerName = "WinIDS"
    accUserName = "Cracker"
    accUserPass = "p@ss"
    
    'This tests for x86 processor architecture, and exits if not. Install is not 64bit capable.
    If getOsType = "x86" Then
    
        'This tests for Windows Windows 7 (6.1), and continues script if not.
    	If getVersionNumber = "6.1" Then
    msgbox "Version detected is : " & getVersionNumber
    	'This forces UAC to be disabled during script execution.
    		If WScript.Arguments.length =0 Then
    			Set objShell = CreateObject("Shell.Application")
    			objShell.ShellExecute "wscript.exe", Chr(34) & _
    			WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
    		Else
    			'Sets registry to disable ELUA, Show Hidden files and folders, and display file extensions.
    			objWShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\EnableLUA", "0", "REG_DWORD"
                'The below two can not be created for user Operator if that account has to be created.
    			objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", "1", "REG_DWORD"
    			objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt", "0", "REG_DWORD"
    				'This changes the computer name for Windows 7.
    				Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    				Set colComputers = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
    				objComputer = "."
    				For Each objComputer In colComputers
    				err = objComputer.Rename(ComputerName)
    				Next
    				Set objWMIService = Nothing
    				Set colComputera = Nothing
    		End if
    	
    	ElseIf getVersionNumber = "5.1" or getVersionNumber = "5.2" Then
    msgbox "Version detected is : " & getVersionNumber
    	'This sets registry to Show Hidden files and folders, and display file extensions.
    		'The below two can not be created for user Operator if that account has to be created.
    		objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\Hidden", "1", "REG_DWORD"
    		objWShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced\HideFileExt", "0", "REG_DWORD"
    		'This changes the computer name for Windows XP or Windows Server 2003.
    		objWShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\ComputerName", computerName
    		objWShell.RegWrite "HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\ParameterS\NV Hostname", computerName
    	Else
    		Msgbox "The OS Product Name is " & getProductName & ", and is not supported!" & VbCrLf & VbCrLf & "Supported Product Names: XP SP3, Server 2003 SP2, and Windows 7",vbokonly,"Detecting Product Name..."
    		WScript.Quit
    	End If
    
    Else
       Msgbox "The detected processor architecture is: " & getOsType & VbCrLf & VbCrLf & "The WinIDS install only supports 32bit architecture at this time!",vbokonly,"Detecting Processor Architecture..."
       WScript.Quit
    End If
    
    'This tests for a specific username and creates a user account if it does not exist. 
    
    msgbox "Checking for " & accUserName & " , and creating if not found."
    QueryForUser(accUserName)
    	'This reates the new username if it doesn't exist
    	Set objNetwork = CreateObject("Wscript.Network")
    		strComputer = objNetwork.ComputerName
    	Set objComputer = GetObject("WinNT://" &strComputer)
    	Set colAccounts = GetObject("WinNT://" & strComputer & "")
    	Set objUser = colAccounts.Create("user", accUserName)
    		objUser.SetPassword accUserPass
    		objUser.Put "UserFlags", 65600
    		objUser.SetInfo	
    
    		'This adds user to Administrators group
    msgbox "Creating new user " & accUserName & " , and adding to Administrators group!"
    	Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
    	Set objUser = GetObject("WinNT://" & strComputer & "/" & accUserName & ",user")
    		objGroup.Add(objUser.ADsPath)
    
    		'This changes the password if the user exists
    	Sub QueryForUser(accUserName)
    	Set objlocal = GetObject("WinNT://.")
    		objlocal.Filter = Array("user")
    	For Each User In objlocal
    		If lcase(User.Name) = lcase(accUserName) Then
    				strComputer = "."
    			Set objUser = GetObject("WinNT://" & strComputer & "/" & accUserName & ", user")
    msgbox "User " & accUserName & "exists and adding password."	
    				objUser.SetPassword accUserPass
    				objUser.SetInfo
    
    			'This checks to see if the user needs added to the Administrators Group
                Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
    				For Each objUser in objGroup.Members
    					If objUser.Name = accUserName Then
    						IsAdmin = "1"
    						End If
    				Next
    
    				if IsAdmin <> "1" Then
    msgbox "Adding existing user " & accUserName & " to Administrator group."
    				Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
    				Set objUser = GetObject("WinNT://" & strComputer & "/" & accUserName & ",user")
    					objGroup.Add(objUser.ADsPath)
    				End If
    		End If    
    Next
    	End Sub
    					
    'This restarts OS in 10 seconds to apply changes.
    msgbox "End of script!"
    'objWShell.Run "shutdown /r /t 10 /f /d P:4:2"
    Set objWShell = Nothing
    I do really appreciate the expert help.
    Last edited by mesteele101; 29th August 2011 at 01:24 PM.

SHARE:
+ Post New Thread
Page 3 of 3 FirstFirst 123

Similar Threads

  1. Need Help with folder ownership in windows 7
    By mrb-solutions in forum How do you do....it?
    Replies: 9
    Last Post: 2nd August 2010, 10:28 AM
  2. Replies: 1
    Last Post: 10th March 2010, 11:56 AM
  3. We need a new website and I need help... please?
    By elsiegee40 in forum EduGeek Joomla 1.5 Package
    Replies: 9
    Last Post: 20th January 2009, 08:53 PM
  4. Replies: 1
    Last Post: 2nd July 2008, 04:20 PM
  5. Need help with Plasma screen install and audio on PE Suite
    By tosca925 in forum How do you do....it?
    Replies: 5
    Last Post: 26th June 2008, 11:41 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •