×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Is this remotely correct?

Is this remotely correct?

Is this remotely correct?

(OP)
I was asked to create a vbscript for work two days ago. Never created one. Still don't understand anything about scripting but it needed to be done. I spent hours trying to figure out the correct format to run things. Basically, I was asked to remove an old cisco anyconnect version and install the new version on all client computers as a startup script for GPO. Plus I would add cisco anyconnect network manager as well. Then I would take a config file and move it the proper directory. Did I mention I do not know what the hell i'm doing. Not sure why this was assigned to me but I feel like a fool to say no. Any comments would help.

CODE -->

'=========================================================================================================================================
'=== START SCRIPT                                                                                                                      ===
'===                                                                                                                                   ===
Option Explicit

Const HKEY_LOCAL_MACHINE = &H80000002
Dim CACProductName, CACProductKey, CACVersion, Msg, MsgBoxStyle, RegKey, CACProductKey, CACProductName, AMCProductKey, CACProductName, AMCProductKey, AMCProductName, AMCVersion, NAMProductKey, NAMProductName
'CAC = Old Cisco AnyConnect
'AMC = New Cisco AnyConnect
'NAM = Network Access Manager
'=========================================================================================================================================
'=== START SUBs                                                                                                                        ===
'===                                                                                                                                   ===
'=========================================================================================================================================
'=== START Check for Cisco AnyConnect Secure Mobility Client v. 3.1.03103                                                                                                ===
'===                                                                                                                                   ===
Sub GetSMCKey()

Dim oReg, sPath, aKeys, sName, sKey, sVersion
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

sPath = "SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, sPath, aKeys

For Each sKey in aKeys
        oReg.GetStringValue HKEY_LOCAL_MACHINE, sPath & "\" & sKey, "DisplayName", sName, "DisplayVersion", sVersion
        If Not IsNull(sName, sDisplay) Then 
            If ((sName = "Cisco AnyConnect Secure Mobility Client") And (sDisplayVersion = 3.1.03103)) Then
				CACProductKey = sKey
				CACProductName = sName
				CACVersion = sVersion
            End If
        End If
Next
End Sub
'===                                                                                                                                   ===
'=== END Check for AnyConnect Secure Mobility Client v. 3.1.03103                                                                                              ===
'=========================================================================================================================================
'=========================================================================================================================================
'=== START Check for Cisco AnyConnect Network Access Manager                                                                          ===
'===                                                                                                                                   ===
Sub GetNAMKey()

Dim oReg, sPath, aKeys, sName, sKey
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

sPath = "SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, sPath, aKeys

For Each sKey in aKeys
        oReg.GetStringValue HKEY_LOCAL_MACHINE, sPath & "\" & sKey, "DisplayName", sName
        If Not IsNull(sName) Then 
            If (sName = "Cisco AnyConnect Network Access Manager") Then
				NAMProductKey = sKey
				NAMProductName = sName
            End If
		End If
Next
End Sub
'===                                                                                                                                   ===
'=== END Check for Cisco AnyConnect Network Access Manager                                                                           ===
'=========================================================================================================================================
'=========================================================================================================================================
'=== START Check for Cisco AnyConnect 3.1.05170                                                                                   ===0
'===                                                                                                                                   ===
Sub GetAMCKey()

Dim oReg, sPath, aKeys, sName, sKey, sVersion
Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

sPath = "SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, sPath, aKeys

For Each sKey in aKeys
        oReg.GetStringValue HKEY_LOCAL_MACHINE, sPath & "\" & sKey, "DisplayName", sName, "DisplayVersion", sVersion
        If Not IsNull(sName) Then 
            If ((sName = "Cisco AnyConnect Secure Mobility Client") And (sVersion = "3.1.05170")) Then
				AMCProductKey = sKey
				AMCProductName = sName
				AMCVersion = sVersion
            End If
        End If
Next
End Sub
'===                                                                                                                                   ===
'=== END Check for Cisco AnyConnect 3.1.05170                                                                                       ===
'=========================================================================================================================================
'=========================================================================================================================================
'=== START Uninstall Cisco AnyConnect 3.1.03103                                                                                   ===
'===                                                                                                                                   ===
Sub UninstallSMC(key, name, version)
Dim cmd, objShell, iReturn, oshell

cmd = "%SystemRoot%\System32\msiexec.exe /q/x " & key
Set objShell = wscript.createObject("wscript.shell")

objShell.LogEvent 0, "Removing the program [" & name & "] under Product Key [" & key & "]" & vbCrLf & "Executing command: " & vbCrLf & cmd

iReturn=objShell.Run(cmd,1,TRUE)
 
	If (iReturn = 0) Then
		objShell.LogEvent 0, "Program [" & name & "] was successfully removed"
	Else
		objShell.LogEvent 0, "Failed to remove the program [" & name & "]."
	End If
 
Set objShell = Nothing  
End Sub
'===                                                                                                                                   ===
'=== END Uninstall Cisco AnyConnect 3.1.03103                                                                                    ===
'=========================================================================================================================================
'===                                                                                                                                   ===
'=== END SUBs                                                                                                                          ===
'=========================================================================================================================================
'=========================================================================================================================================
'===== Overwrite existing Configuration.xml
'if file does not exist in folder then copy file from source OR
'if file does exist, overwrite existing file

strFileToCopy = "\\mydomain.com\softdist\Software\CiscoISE\configuration.xml"
strFolder = "C:\ProgramData\Cisco\"


Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")

 
If objFSO.FolderExists(strFolder) Then
  objFSO.CopyFile strFileToCopy, strFolder, OverwriteExisting  
Else
  Wscript.Echo "Target Folder does not exist."
End If
'=========================================================================================================================================
'=== START CALLs (This is the script's logic.)                                                                                         ===
'=========================================================================================================================================                                                                                                                           

Call GetSMCKey()

	If Not (CACProductKey = "") Then
		Call UninstallSMC(CACProductKey, CACProductName, CACVersion)
	End If

	
AMCProductKey = ""
AMCProductName = ""
AMCVersion = ""

Call GetAMCKey()

	If (AMCProductKey = "") Then
		Dim objWSH
		Set objWSH = CreateObject("WScript.Shell")
		'Now we need to produce "msiexec.exe /a "Msi file.msi" /quiet /norestart" for a silent MSI install
		objWsh.Run "msiexec.exe /i " + Chr(34) + "\\mydomain.com\softdist\Software\CiscoISE\AnyConnectMobilityClient\anyconnect-win-3.1.05170-pre-deploy-k9.msi" + Chr(34) + " /quiet /norestart"
	End If
	
	If (NAMProductKey = "") Then
		Dim objWS
		Set objWS = CreateObject ("WScript.Shell")
		objWS.Run "msiexec.exe /i " + Chr(34) + "\\mydomain.com\softdist\Software\CiscoISE\AnyConnectMobilityClient\anyconnect-nam-win-3.1.05170-k9.msi" + Chr(34) + " /quiet /norestart"
	Else
		Wscript.Quit
	End If
'===                                                                                                                                   ===
'=== END CALLs                                                                                                                         ===
'=========================================================================================================================================
'===                                                                                                                                   ===
'=== END SCRIPT                                                                                                                        ===
'================================================================================================= 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close