Jump to content

Need help in sorting these scripts out and possible better solutions.


Recommended Posts

Posted

This is what I've tested with Windows 7, XP and Server 2003. Processor architecture detection has also been tested.

 

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")

If getOsType = "x86" Then 'Tests for x86 processor architecture and eXits if not.
  If getVersionNumber = "6.1" Then 'Tests for Windows Windows 7 install and continues if not. 
  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"
  ElseIf getVersionNumber = "5.2" Or "5.1" Then 'Tests for Windows XP or Windows Server 2003 and eXits if not.
     WshShell.Popup "How Do You Feel?", 5, "Good Morning:", 0 + 48
     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"
  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

' To do: Change Computer name - Complete - XP, Server 2003, and Windows 7

' Add User Account Plus - XP, Server 2003, and Windows 7

objWShell.Run "shutdown /r /t 10 /f /d P:4:2" 'Restarts OS in 10 seconds to apply changes.

Set objWShell = Nothing

Posted (edited)

Ok, I started on the next section, and need a little help in getting it cleaned up and changed a little. I'm not at all sure how to edit this correctly, so any help would be great.

 

This section changes the computer name.

 

1) Can the error checking be removed?

 

2) Can the "Machine successfully renamed..." be removed?

 

3) Can the "The OS is not 7, Vista, XP, or 2K3..." be removed?

 

All I need it to do is just bounce through the code with no display. If it's 6.1 then execute that part and continue to the next section of the script to change the user name.

If it's not 6.1 then jump to the section for 5.2 or 5.1, and execute with no checking, because at this point it has to be 5.2 or 5.1, and then jump to the section to change the user name.

 

'This section changes the computer name.
ComputerName = "WinIDS"
If getVersionNumber = "6.1" Then
     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
        Msgbox "Machine successfully renamed to " & computerName
     End If

     Set objWMIService = Nothing
     Set colComputera = Nothing

  ElseIf getVersionNumber = "5.2" or "5.1" Then
     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 is not 7, Vista, XP, or 2K3. The OS Version number is: " & getVersionNumber
  End If
Else
  
End If

'This section will add or changes the user name
'To be continued...

TIA

Edited by mesteele101
Posted (edited)

Not sure if this will help with part of the script but if you use the select case method , it may make it easier and neater to read ie

 

Select Case getVersionNumber

 

Case 5.1:

'Code here to execute if it is 5.1

 

Case 5.2:

 

'Code here to execute if it is 5.2

 

Case 6.1:

 

'code here to execute if it is 6.1

 

End Select

 

I think you can use OR or AND if you want to make it so that if it is 5.1 or 5.2 then it executes the same chunk of code ie

 

Select Case getVersionNumber

 

Case 5.1 OR 5.2:

 

'code here to execute if it is either 5.1 or 5.2

 

Case 6.1:

 

'code here to execute if 6.1

 

End Select

 

When combing or checking multiple values I can't remember if you need to enclose each value in quotes ie

 

"5.1" OR "5.2"

 

You are also better off having the error checking so personally I would keep it in there where possible, I presume you are reffering to the

 

If err <> 0 Then

Else

Computer was renamed succesfully

End If

 

 

With regards to the error message about this is not windows 7, xp or 2003 can be removed but then how are you advising your user that the code will not execute or run because it is not the correct OS ?

 

The same with the computer has been renamed or not , you can remove the msgbox alerts but then the user has no way of knowing if it was done or not

Edited by mac_shinobi
Posted

There is another section of script that goes above this one that is completed. It does all the checking and when it gets to this part of the script it has to be either 6.1, 5.2, or 5.1

 

The script above works it just needs the sections removed and cleaned up by someone that has theses skills. It wopuld be a lot of trial and error for the inexperianced.

Posted

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.

 

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

Posted (edited)

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.

 

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:

 

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?

Edited by mesteele101
Posted

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

 

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

Posted

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.

 

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?

 

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"

Posted

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

 

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


 

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 ?

Posted

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.

Posted
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 ??

Posted (edited)

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.

 

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.

Edited by mesteele101
Posted (edited)

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.

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.

Edited by mesteele101

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...