Archive for category Scripting

Scripting Sybase PowerDesigner Viewer 16.x

Ran into a curious situation when automating the installation of Sybase PowerDesigner Viewer 16.  If you just want the answer, then jump to the bottom of this post :-)

The installer was built as a self-extracting InstallShield setup.  Typically, for a ConfigMgr package I like to use the extracted files.  However, when attempting to run the Setup of the InstallShield installation, an error was generated that “setup.cab” was missing from “Disk2″.  This was issue #1.

Since there was no “disk 2″, so I reverted back to just using the native, self-extracting installer.  This appeared like it was going to be fairly simple as all defaults were going to be used.  Most times, just using /s is enough to complete the silent installation.  But no, this would be too easy.  The installation would still not run unattended.  Eventually I discovered that the only way to automate a silent installation was to create and include a setup.iss record file.  Again, this is despite that only the defaults were being used and that a basic setup.iss was already included as part of the extracted files.  This was issue #2.

So have we finally figured out how to automate the silent install?  Of course not – there is no reason that a simple application should be so easy to automate.  Running the install as PDV_16.exe /s /f1″setup.iss” would absolutely install PDV…when executed manually.  As soon as it was deployed using ConfigMgr, the setup would fail with an error.  Why oh why!?!  Turns out that their installer also hates to be run in System context.  Which is what we all know is how ConfigMgr needs to do it, especially for Task Sequences.  This was issue #3.

After tussling with this application, I finally figured out that not only is a recorded installation (setup.iss) necessary, but so is specifying a location for the log file!!  Conclusion?  I despise Sybase installers.  Answer?  Use the following command line.

PDV_16.exe /s /f1"setup.iss" /f2"c:\windows\temp\pdvsetup.log"

One last comment.  Make sure the log file is specified in a directory that already exists (such as c:\windows\temp), otherwise you end up with Issue #4.  And use a wrapper (such as a batch file) to specify the current working directory of the setup.iss file, otherwise you’ll end up with Issue #5.  If using a batch file, the command would like this for your ConfigMgr package:

"%~dp0PDV_16.exe" /s /f1"%~dp0setup.iss" /f2"c:\windows\temp\pdvsetup.log"

Leave a Comment

Installing VMware View Agent in a Task Sequence

The VMware View agent is deployable as an MSI file and uses basic command line parameters.  However, I recently had significant difficulties with getting it to install within a ConfigMgr Task Sequence as part of an OS image deployment.  Despite that the agent could be installed manually using the parameters, in a TS the installer would fail (e.g. return a non-success exit code) and thus fail the TS.

Through investigation, the agent’s install log file (located in %windir%\temp\) stated error 1603 and a message that if failed due to a detected pending restart.  So in the TS, I added a pre-restart command prior to the install…..but that still did not solve the problem.  Several various other solutions were attempted, but all to no avail.

Eventually I found a VMware KB article which outlined the issue.  It was being caused by multiple registry keys – FileRenameOperations, Run, and RunOnce.  So I created  a quick batch script to

  1. Backup the reg keys to %windir%\temp
  2. Delete the reg keys
  3. Run the install
  4. Restore the reg keys
:: Backup problem registry keys for VMware Agent Install
reg.exe EXPORT "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager" c:\windows\temp\hklmsession.reg /y
reg.exe EXPORT "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" c:\windows\temp\hklmrun.reg /y
reg.exe EXPORT "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" c:\windows\temp\hklmrunonce.reg /y

:: Delete problematic registry keys
reg.exe DELETE "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager" /v PendingFileRenameOperations /f
reg.exe DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /va /f
reg.exe DELETE "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /va /f

:: Install VMware agent
xcopy "%~dp0VMware-viewagent-x86_64-5.0.1-640055.exe" c:\windows\temp /y
c:\windows\temp\VMware-viewagent-x86_64-5.0.1-640055.exe /s /v" /qn REBOOT=R"

:: Restore registry keys
reg.exe IMPORT c:\windows\temp\hklmsession.reg
reg.exe IMPORT c:\windows\temp\hklmrun.reg
reg.exe IMPORT c:\windows\temp\hklmrunonce.reg

del c:\windows\temp\hklm*.reg
exit

However, this still wasn’t good enough to solve the problem! The .msi needed to be copied locally to execute AND this needed to be run with 64-bit redirection disabled.  It was a mess to figure out and test, but I was able to eventually discover the right combination to have the agent automatically in a Task Sequence!

vmware_view_agent

Leave a Comment

Script to Rename Computer During OSD

In assisting a recent customer implement an upgrade from WinXP to Win7, they requested that the names be changed to fit a new standard as part of the in-place imaging process.  In this particular case, all of the computers had a name that ended with a sequential number (1, 2, 3, …) plus an “A” tacked on at the end.  They wanted the “A” removed and for the PC name just to end with the sequential number.

This was a pretty easy fix to accomplish through a VBScript which

  1. Retrieves the active OSDComputerName task sequence variable
  2. Detects if the last letter is an “A”
  3. Truncates the name to remove the “A”
  4. Re-sets OSDComputerName to the new value

'==========================================================================
' NAME: PCNameStandardization.vbs
' AUTHOR: Nick Moseley, <a href="http://t3chn1ck.wordpress.com">http://t3chn1ck.wordpress.com</a>
' COMMENT: This script will detect if the current computer name ends with ' the letter 'A' so that it can be removed.
'==========================================================================
Option Explicit
Dim oTaskSequence, sComputerName, iNameLength
Set oTaskSequence = CreateObject ("Microsoft.SMS.TSEnvironment")

sComputerName = ucase(oTaskSequence("OSDComputerName")) iNameLength = Len(sComputerName)

If right(sComputerName,1) = "A" Then
oTaskSequence("OSDComputerName") = left(sComputerName, iNameLength-1)
  ' The echo statement is not displayed, but rather registered in SMSTS.log
wscript.echo ">>>> Set OSDComputerName from " & sComputerName & " to " & oTaskSequence("OSDComputerName")
End If

To add this into your task sequence:

  1. Put this script into a package for your general OSD Scripts
  2. Ensure you have the step to capture the computer name
    CaptureWinSettings
  3. Immediately after the capture windows settings, run the PC Standardization Script
    PCNameStandardization
  4. On whatever step you have that prompts for the PC Name, add a condition to not execute if variable OSDComputerName does not exist.  This is so that task sequence will not be held up on the other end waiting for someone to enter a PC name for one you’ve already set.
    PromptPCNameCondition
  5. Finally – ensure ConfigMgr environment is configured to automatically resolve conflicting records!  See this as to why http://t3chn1ck.wordpress.com/2013/02/14/error-initializing-client-registration-0×80040222/

,

2 Comments

VBScript Disable NIC Power Management Setting

The following VBScript will disable NIC power save features.

'==========================================================================
' NAME: SetNetworkPnPCapabilities
' AUTHOR: Nick Moseley , Archstone
' COMMENT: Parses list of available network adapters to then disable power
' save features.  For more info, see Microsoft KB837058
' VERSION HISTORY:
' 1.0 (05/09/2011) - Initial script
' 1.1 (05/10/2011) - Fixed logical bug within the If statement for Wan/Lan
' 2.0 (05/10/2011) - Added logging into registry for future inventory
' 3.0 (08/17/2011) - Commented out changes to disable NIC power save as
'  this needs to be enabled in order to support WOL
'==========================================================================
Option Explicit
Const ForAppending = 8

Dim oShell, oWMI, colNetworkAdapterItems, sNetworkAdapterReg
Set oShell = CreateObject ("WScript.Shell")
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set colNetworkAdapterItems = oWMI.ExecQuery ("Select * from Win32_NetworkAdapter")
sNetworkAdapterReg = "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\"

' Logging
Dim oFSO, oVersionLog
Set oFSO = CreateObject ("Scripting.FileSystemObject")
Set oVersionLog = oFSO.OpenTextFile ("C:\Windows\Version.log", ForAppending, True)
oVersionLog.WriteLine "Configuration of Network Adapters"
oVersionLog.WriteLine "  => Started (" & Date & " " & Time & ")"

' Get all objects and take action on network adapters
Dim oItem, sIndexValue, sLomValue
For Each oItem In colNetworkAdapterItems
 If InStr(lcase(oItem.Name),"wan miniport")=0 _
   And InStr(LCase(oItem.Name),"microsoft isatap")=0 _
   And Trim(oItem.Name)<>"RAS Async Adapter" _
   And InStr(LCase(oItem.Name),"cisco")=0 Then
  If oItem.Index < 10 Then
   sIndexValue = "000" & oItem.Index
  Else
   sIndexValue = "00" & oItem.Index
  End If
  
  ' ****************************************
  ' IMPORTANT: NIC power save as needs to be enabled in order to support WOL
  ' Configure/disable Power save on NIC
  oShell.RegWrite sNetworkAdapterReg & sIndexValue & "\PnPCapabilities", "56", "REG_DWORD"
  oVersionLog.WriteLine "  => Disabled network adapter power save on device """ & oItem.Name & """"
  oVersionLog.WriteLine "     Set PnPCapabilities (dword) to 38 in " & sNetworkAdapterReg & sIndexValue
  ' ****************************************
  
  ' Configure/enable WAN/LAN switching
  sLomValue = ReadRegistryKey (sNetworkAdapterReg & sIndexValue, "LOM")
  If sLomValue<>"1"  And sLomValue<>"null" Then
   oShell.RegWrite sNetworkAdapterReg & sIndexValue & "\LOM", "1", "REG_SZ"
   oVersionLog.WriteLine "  => Enabled WAN/LAN switching on device """ & oItem.Name & """"
   oVersionLog.WriteLine "     Set LOM (string) to ""1"" in " & sNetworkAdapterReg & sIndexValue
  End If  
 End If
Next
' Set registry values for SCCM inventory
oShell.RegWrite "HKLM\Software\CompanyName\Image Info\DisabledNICPowerSave", "True", "REG_SZ"

' End
oVersionLog.WriteLine "  => Completed (" & Date & " " & Time & ")"
WScript.Quit (oVersionLog.Close)

Function ReadRegistryKey (sReadKey, sReadValue)
 On Error Resume Next
 Dim sGetValue
 sGetValue = oShell.RegRead (sReadKey & "\" & sReadValue)
 
 If Err.Number <> 0 Then
  ReadRegistryKey = "null"
 Else
  ReadRegistryKey = cstr(sGetValue)
 End If  
End Function

Leave a Comment

Custom query of ACT data for apps with issues

The application compatibility toolkit (ACT) is a great tool for analyzing compatibility of apps when doing a migration of Windows.  However, the available “reports” are limited in what they display out-of-box.  Fortunately since the tool is a SQL database, we can write our own queries to get what we need.  The below procedure/query will identify business specific apps and the detected compatibility issues.

  1. Create and customize an ACT query (within the compatibility manager) which identifies your specific business software
  2. Select all of the apps listed
  3. Create a new custom category “Priority Business Apps”
    • For the primarily used business apps, create/select sub category “PrimaryApps”
    • For the secondarily used business apps, create/select sub category “SecondaryApps”
      ACTCategories
  4. Run the following query against the ACT database
    Select distinct CAQ.subCategory, AR.AppName, LI.issueID, AIQ.severity, LI.title, LI.Details
    from Applications AR
    join AppReport_Issues_Query AIQ on AIQ.appID=AR.identity_hash
    join Categorized_Applications_Query CAQ on CAQ.objectID=AR.identity_hash
    join Localized_Issue LI on LI.issueID=AIQ.issueID
    where CAQ.category='Priority Business Apps'
    
  5. Copy the results into Excel

AppIssuesQuery

,

Leave a Comment

Standalone Imaging Solution

I’ve been in a situation a couple of times where a client was going to use a third-party vendor to image hardware offsite, but didn’t have Microsoft deployment tools (WAIK, WDS, MDT, SCCM, etc.) for deploying the standard WIM image that was created.  To work with this scenario, I developed an unattended answer file with WSIM that can be used to sysprep a computer for an image where the disk can be cloned.  This sysprep file essentially does the following items below.  Many of the items may seem “unnecessary”, but they are necessary in order to automate the majority of the deployment.

Sysprep.xml Features

  • enables the local admin account
  • removes the “copy profile” functionality
  • removes the “Get Windows Live” shortcuts
  • sets the time zone to MST
  • enables RDP
  • disables firewall notifications
  • disables the domain firewall
  • disables Windows Defender
  • disables IE accelerators
  • disables the IE first run wizard
  • enables IE compatibility mode
  • disables IE suggested sites
  • sets Windows to skip auto activation
  • disables system restore
  • sets the local language to English
  • sets the registered owner/org
  • sets Windows to automatically login as Administrator one time
  • sets the screen resolution to 1024×768
  • sets the first logon command to execute a script in C:\CompanyName
  • Hides the Windows EULA Hides the wireless network setup wizard
  • sets the default network location to “Work”
  • sets the recommended level of protection for Windows Update
  • creates taskbar links to Outlook and Word

Download sysprep.xml here!!

Next, the overall process looks like such:

  1. Automate driver installation using HP SoftPaqs and script to copy the files into C:\CompanyName\ModelName\
    1. Optionally, automate and script BIOS updates
  2. Create script named “ImageConfigTasks.vbs” (code below) to do the following items (this will run post sysprep).  Script should be copied into C:\CompanyName.  You can use the attached script as a starting point.
    1. Prompt for PC name
    2. Detect PC model and install drivers (do this next to ensure the NIC driver gets installed for the domain join)
    3. Join to domain and OU
    4. Install SCCM client
    5. Install SCEP client
    6. Restart Window
  3. Create sysprep.xml file with x64 bits which essentially allows the PC to auto logon into Windows with the admin account and launches ImageConfigTasks.  You can use the attached sample as guidance, but do not actually use this file as it was compiled for the x86 components and you need it for x64.
  4. Create a “build” task sequence which installs Windows, software, security updates, copy of the drivers into the CompanyName folder, copy of the ImageConfigTasks script, copy the sysprep.xml file
  5. Run the task sequence on a VM
  6. After completion, login to Windows and run %SYS32%\sysprep\sysprep.exe /generalize /oobe /shutdown /unattend:C:\CompanyName\sysprep.xml
    1. This will sysprep the PC’s disk for cloning.  Do not power on the PC once its shutdown!
    2. Optionally, you can creatively automate this process so that you do not need to actually login to the PC
  7. Once the PC with the cloned disk has been delivered onsite, power on the PC.  Windows will go through mini-setup to install generic devices.  Then Windows will auto logon to run the script and complete the setup process.

Download the ImageConfigTasks script here!!

Run on physical hardware

To build-out this custom solution for the vendor, do the following.

  1. Complete and “certify” the newly captured image (note: this is still in progress as of 12:15 PM today, but is looking good to complete successfully).
  2. Use the deployment task to install this image AND the hardware drivers AND any other software/configurations that did not make it into the image.  You may also want to change the task sequence to NOT join to the domain for this model so that it does not receive [junky] group policies.
  3. Once that task sequence is done, login to Windows as the local admin account.
  4. Ensure the two script files live in C:\CompanyName
  5. Run %SYS32%\sysprep\sysprep.exe /generalize /oobe /shutdown /unattend:C:\CompanyName\sysprep.xml
  6. DO NOT TURN THE COMPUTER ON.  Remove the hard drive and give to vendor.  Once a cloned PC is onsite and connected to the network, only then should the PC be turned on.  A prompt for the computer name will appear and then the custom script will execute.

While you’re in the process of testing/development, you can of course turn it on to validate the scripts execute, drivers are installed, etc.

, ,

2 Comments

VBScript to Delete HKCU values or keys

Based upon my VBScript to create HKCU registry keys and/or values, I’ve created a script that does the opposite of deleting keys and/or values.  This code was also updated to locate the default user profile path for Windows 7 (and newer).

'==========================================================================
' Author: Nick Moseley, http://t3chn1ck.wordpress.com
' Comments: This script will parse all User profiles on the computer, load their  HKCU hive,
'    then set the appropriate registry keys.
' History: '    1.0 (04/07/2009) - Initial script
'    1.1 (06/03/2009) - Added example for setting dword values based on MyITForum question
'    1.2 (06/05/2009) - Added additional comments to identify the section where to define the values to be set
'    1.3 (09/23/2010) - Corrected comment typos
'    2.0 (11/12/2012) - Changed base script to DELETE specified keys/values
'==========================================================================
Option Explicit
Const ForAppending = 8
Const HKLM = &H80000002
' ************************************************
' Configure the following values to define the HKCU keys to be deleted
' ************************************************
Const sUserKey = "\Software\SampleKey"
Const sUserKeyValueName = "SampleValueName"
' ************************************************
Dim oReg, oFSO, oFile, oUserSubkey, aUserProfiles, oShell
Dim sProfileLCase, sRegExe, sRegLoad, sRegUnload, sHiveName, sSubPath, sProfile, sValueName, sKeyPathUserProfiles, sValue, ReturnVal
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
Set oShell = CreateObject ("WScript.Shell")
Set oFSO = CreateObject ("Scripting.FileSystemObject")
' Begin configuration of existing user profiles
sValueName = "ProfileImagePath"
sKeyPathUserProfiles = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
sRegExe = "C:\Windows\system32\reg.exe"
oReg.EnumKey HKLM, sKeyPathUserProfiles, aUserProfiles
' Parse all user keys
For Each oUserSubkey In aUserProfiles
    sSubPath = sKeyPathUserProfiles & "\" & oUserSubkey
    oReg.GetExpandedStringValue HKLM,sSubPath,sValueName,sValue
    sProfile = Split(sValue, "\")
    sProfileLCase = LCase(sProfile(2))
     If sProfileLCase = "system32" Then
         ' Do nothing
     ElseIf sProfileLCase = "localservice" Then
        ' Do nothing
     ElseIf sProfileLCase = "networkservice" Then
        ' Do nothing
      ElseIf sProfileLCase = "serviceprofiles" Then
        ' Do nothing
      Else
          sHiveName = "TempHive_" & sProfileLCase
      ' Load user's profile hive into a temp location
          sRegLoad = " LOAD HKLM\" & sHiveName & " """ & sValue & "\ntuser.dat"""
          oShell.Run sRegExe & sRegLoad, 0, True
         ' Call subroutine to change registry key
        SetConfigUserHive (sHiveName)
         ' Unload user's profile hive
        sRegUnload = " UNLOAD HKLM\" & sHiveName
       oShell.Run sRegExe & sRegUnload, 0, True
      End If
Next
' Default User Profile sHiveName = "TempHive_DefaultUser"
sRegLoad = " LOAD HKLM\" & sHiveName & " ""C:\Users\Default\ntuser.dat"""
oShell.Run sRegExe & sRegLoad, 0, True
SetConfigUserHive (sHiveName)
sRegUnload = " UNLOAD HKLM\" & sHiveName
oShell.Run sRegExe & sRegUnload, 0, True
' End script
WScript.Quit ()
Sub SetConfigUserHive (sTempHive)
    Dim sTempHiveKeyPath
    ' Path of registry keys
    sTempHiveKeyPath = sTempHive & sUserKey
   'wscript.echo "sHiveName = " & sTempHiveKeyPath
    ' Delete value
    ReturnVal = oReg.DeleteValue(HKLM, sTempHiveKeyPath & "\", sUserKeyValueName)
     ' Delete key
     ReturnVal = oReg.DeleteKey(HKLM, sTempHiveKeyPath & "\", sUserKey)
End Sub

10 Comments

Removing Desktop Shortcuts for First Dispute Client

I was in a recent situation where I needed to create an install package for First Data’s FirstDispute client, but to eliminate the shortcuts.  It could have been easy to just install the software and then delete the shortcuts with a script, but instead I decided to dig around into the MSI with Microsoft Orca.  Within the MSI properties I found table “Shortcut” and items Client_Desktop, Tracking_System_Desktop, and HostReportSystem_Desktop.  By simply “dropping” these items and then saving this as a transform, I was then able to deploy the software along with the TRANSFORMS property to eliminate the desktop shortcuts.

To do this on your own:

  1. Download and install Orca (available in any Windows SDK)
  2. Open Orca
  3. Go to File > Open.  Browse to and open the MSI file for the FirstDispute client
  4. Find Table “shortcuts”
  5. Right-click each shortcut to be removed and select “drop row”
  6. Save the file as a new transform (.mst) file as NoDesktopShortcuts.mst
  7. Run the install as FirstDisputClient.msi TRANSFORMS=NoDesktopShortcuts.mst

2 Comments

ConfigMgr Client GPO Assignment Removal

On a recent upgrade project of ConfigMgr 2007 to 2012, the company I was assisting with the upgrade had previously deployed a group policy to enforce the client assignment to the 2007 site code.  However, simply removing the GPO could not correct the situation as the value was “tattooed” into the registry.  So as part of the ConfigMgr client upgrade, I included the below script to revoke the registry key.


' ***********************************************************
' This script was created by <a href="http://t3chn1ck.wordpress.com/">http://t3chn1ck.wordpress.com</a> to 
' delete the following registry value. The value will prevent 
' the abilityof anSCCM client to become reassigned to the new
' ConfigMgr 2012 site.
' HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\SMS\Mobile Client\
' GPRequestedSiteAssignmentCode (REG_SZ) = ""
' ***********************************************************
Option Explicit
Const HKLM = &H80000002 Const sRegKey = "SOFTWARE\Microsoft\SMS\Mobile Client"
Const sRegValueName = "GPRequestedSiteAssignmentCode"
Dim oReg, iReturnValue
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
iReturnValue = oReg.SetStringValue (HKLM, sRegKey, sRegValueName, "")
wscript.quit iReturnValue

, ,

10 Comments

Batch File to Schedule WinXP Restart

In a troubleshooting situation with Windows XP hanging during a restart of Windows after a CM07 package deployment, I built a workaround script that creates a scheduled task to perform a forced Windows restart (for 2 minutes after install completion).  The reason for doing 2 minutes is because there are times when the scheduled task can be created in the 59th second of a minute, but there isn’t enough time for the installation to exit.

@echo off 
Set /a MIN=%TIME:~3,2% + 2 
Set /a HOUR=%TIME:~0,2%
:: Remove the echo command to actually schedule the restart 
echo at %HOUR%:%TIME% /interactive C:\Windows\system32\shutdown.exe -r -t 60 -f

Leave a Comment

Follow

Get every new post delivered to your Inbox.

Join 59 other followers