ohjeet:skriptit
Erot
Tämä näyttää erot valitun ja nykyisen version kesken tästä sivusta.
Both sides previous revisionEdellinen revisioSeuraava revisio | Edellinen revisio | ||
ohjeet:skriptit [2010/10/13 14:22] – mikko | ohjeet:skriptit [2015/09/21 11:46] (nykyinen) – [Luo package ja programsit Configuration Manageriin] matronka | ||
---|---|---|---|
Rivi 5: | Rivi 5: | ||
==== Onko koneelle kirjautunut käyttäjä domain-käyttäjä ==== | ==== Onko koneelle kirjautunut käyttäjä domain-käyttäjä ==== | ||
+ | Seuraava VBScript-koodinpätkä hakee koneelle kirjautuneen käyttäjän tiedot ympäristömuuttujista ja tarkistaa onko käyttäjä domain-tunnus vaiko ei. | ||
+ | <code vb> | ||
+ | Set objShell = CreateObject(" | ||
+ | Set objProcEnv = objShell.Environment(" | ||
+ | strUserName = objProcEnv(" | ||
+ | strUserDomain = objProcEnv(" | ||
+ | strUserDNSDomain = objProcEnv(" | ||
+ | If strUserDNSDomain <> " | ||
+ | strValue = " | ||
+ | answer = MsgBox(strValue, | ||
+ | WScript.Quit ' palautetaan -10, jos ei ole utu-domainin käyttäjä | ||
+ | </ | ||
+ | |||
+ | ==== Onko prosessi käynnissä ==== | ||
+ | |||
+ | VBSkript-funktio, | ||
+ | <code vb> | ||
+ | Function isProcessRunning(strIn) | ||
+ | |||
+ | Set objWMIService = GetObject(" | ||
+ | Set colProcesses = objWMIService.ExecQuery(" | ||
+ | |||
+ | If colProcesses.Count > 0 Then | ||
+ | isProcessRunning = True | ||
+ | Else | ||
+ | isProcessRunning = False | ||
+ | End If | ||
+ | End Function | ||
+ | </ | ||
- | ==== x86-ympäristö | + | ==== x86 vaiko x64 ==== |
Seuraavalla VBScript-funktiolla saat selville käyttöjärjestelmän bittisyyden | Seuraavalla VBScript-funktiolla saat selville käyttöjärjestelmän bittisyyden | ||
Rivi 14: | Rivi 43: | ||
64-bittisessä ympäristössä aidosti 64-bittisessä Windowsissa. | 64-bittisessä ympäristössä aidosti 64-bittisessä Windowsissa. | ||
- | < | + | < |
' Finds out Real Operating System architecture (despite the running process image type) | ' Finds out Real Operating System architecture (despite the running process image type) | ||
' Returns: 0: OS architecture not found (or propably Intel Itanium) | ' Returns: 0: OS architecture not found (or propably Intel Itanium) | ||
Rivi 21: | Rivi 50: | ||
Function GetOSArchitecture | Function GetOSArchitecture | ||
- | | + | |
Set objProcEnv = objShell.Environment(" | Set objProcEnv = objShell.Environment(" | ||
| | ||
Rivi 41: | Rivi 70: | ||
End Function | End Function | ||
+ | </ | ||
+ | ==== x64 - registryn käsittely ==== | ||
+ | Seuraavat VBScript-funktiot (**EnumRegKey**, | ||
+ | |||
+ | <code vb> | ||
+ | ' --- Enumerates registry keys from the local computer' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | Function EnumRegKey (RootKey, Key, RegType) | ||
+ | Dim objCtx, objLocator, objReg, objInParams, | ||
+ | | ||
+ | Set objCtx = CreateObject(" | ||
+ | objCtx.Add " | ||
+ | objCtx.Add " | ||
+ | |||
+ | Set objLocator = CreateObject(" | ||
+ | Set objReg = objLocator.ConnectServer("", | ||
+ | |||
+ | Set objInParams = objReg.Methods_(" | ||
+ | objInParams.hDefKey = RootKey | ||
+ | objInParams.sSubKeyName = Key | ||
+ | |||
+ | Set objOutParams = objReg.ExecMethod_(" | ||
+ | |||
+ | EnumRegKey = objOutParams.sNames | ||
+ | End Function | ||
+ | |||
+ | |||
+ | ' --- Reads a REG_SZ value from the local computer' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | Function ReadRegStr (RootKey, Key, Value, RegType) | ||
+ | Dim objCtx, objLocator, objReg, objInParams, | ||
+ | |||
+ | Set objCtx = CreateObject(" | ||
+ | objCtx.Add " | ||
+ | objCtx.Add " | ||
+ | |||
+ | Set objLocator = CreateObject(" | ||
+ | Set objReg = objLocator.ConnectServer("", | ||
+ | |||
+ | Set objInParams = objReg.Methods_(" | ||
+ | objInParams.hDefKey = RootKey | ||
+ | objInParams.sSubKeyName = Key | ||
+ | objInParams.sValueName = Value | ||
+ | |||
+ | Set objOutParams = objReg.ExecMethod_(" | ||
+ | |||
+ | ReadRegStr = objOutParams.sValue | ||
+ | |||
+ | End Function | ||
+ | |||
+ | ' --- Creates registry key to the local computer' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | Function CreateRegKey (RootKey, Key, RegType) | ||
+ | Dim objCtx, objLocator, objReg, objInParams | ||
+ | | ||
+ | Set objCtx = CreateObject(" | ||
+ | objCtx.Add " | ||
+ | objCtx.Add " | ||
+ | |||
+ | Set objLocator = CreateObject(" | ||
+ | Set objReg = objLocator.ConnectServer("", | ||
+ | |||
+ | Set objInParams = objReg.Methods_(" | ||
+ | objInParams.hDefKey = RootKey | ||
+ | objInParams.sSubKeyName = Key | ||
+ | |||
+ | objReg.ExecMethod_ " | ||
+ | |||
+ | End Function | ||
+ | |||
+ | |||
+ | ' --- Creates a REG_SZ type registry Key on value to the local computer' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | Function CreateRegStringValue (RootKey, Key, Name, Value, RegType) | ||
+ | Dim objCtx, objLocator, objReg, objInParams | ||
+ | | ||
+ | Set objCtx = CreateObject(" | ||
+ | objCtx.Add " | ||
+ | objCtx.Add " | ||
+ | |||
+ | Set objLocator = CreateObject(" | ||
+ | Set objReg = objLocator.ConnectServer("", | ||
+ | |||
+ | Set objInParams = objReg.Methods_(" | ||
+ | objInParams.hDefKey = RootKey | ||
+ | objInParams.sSubKeyName = Key | ||
+ | objInParams.sValueName = Name | ||
+ | objInParams.sValue = Value | ||
+ | | ||
+ | objReg.ExecMethod_ " | ||
+ | |||
+ | End Function | ||
</ | </ | ||
+ | |||
+ | ==== Onko ohjelman tietty versio asennettuna? | ||
+ | <code vb> | ||
+ | Option Explicit | ||
+ | Dim oShell | ||
+ | Dim regPath | ||
+ | Dim version | ||
+ | |||
+ | Set oShell = CreateObject(" | ||
+ | |||
+ | Select Case GetOSArchitecture | ||
+ | Case 32 ' x86 | ||
+ | RegPath = " | ||
+ | Case Else ' x64 | ||
+ | RegPath = " | ||
+ | End Select | ||
+ | |||
+ | On Error Resume Next | ||
+ | version = oShell.RegRead(RegPath) | ||
+ | On Error Goto 0 | ||
+ | |||
+ | If version = " | ||
+ | wScript.Echo(" | ||
+ | End If | ||
+ | | ||
+ | wScript.Quit | ||
+ | </ | ||
+ | |||
+ | ==== Luo package ja programsit Configuration Manageriin ==== | ||
+ | <code powershell> | ||
+ | |||
+ | #Set the program to be run only on x64 systems. | ||
+ | Function SetOperatingSystemsx64 { | ||
+ | $Program = $Args[0] | ||
+ | |||
+ | $OSystemsx64 = @(@(" | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | $OS_Details = @() | ||
+ | |||
+ | ForEach ($Plat in $OSystemsx64) { | ||
+ | $NewOS = ([wmiclass]" | ||
+ | $NewOS.MaxVersion = $Plat[0] | ||
+ | $NewOS.MinVersion = $Plat[1] | ||
+ | $NewOS.Name = "Win NT" | ||
+ | $NewOS.PlatForm = " | ||
+ | $NewOS *>$Null | ||
+ | |||
+ | $OS_Details = $OS_Details + $NewOS | ||
+ | } | ||
+ | |||
+ | $Program.Get() | ||
+ | $Program.SupportedOperatingSystems = $OS_Details | ||
+ | $Program.Put() | ||
+ | } | ||
+ | |||
+ | #Set the program to be run only on x86 systems. | ||
+ | Function SetOperatingSystemsx86 { | ||
+ | $Program = $Args[0] | ||
+ | |||
+ | $OSystemsx86 = @(@(" | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | | ||
+ | |||
+ | ForEach ($Plat in $OSystemsx86) { | ||
+ | $NewOS = ([wmiclass]" | ||
+ | $NewOS.MaxVersion = $Plat[0] | ||
+ | $NewOS.MinVersion = $Plat[1] | ||
+ | $NewOS.Name = "Win NT" | ||
+ | $NewOS.PlatForm = " | ||
+ | $NewOS *>$Null | ||
+ | |||
+ | $OS_Details = $OS_Details + $NewOS | ||
+ | } | ||
+ | |||
+ | $Program.Get() | ||
+ | $Program.SupportedOperatingSystems = $OS_Details | ||
+ | $Program.Put() | ||
+ | } | ||
+ | |||
+ | Function CreateProgram { | ||
+ | If(!(Get-Module ConfigurationManager)) {Import-Module " | ||
+ | cd TUY: | ||
+ | |||
+ | New-CMProgram ` | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | $CMProgram = Get-CMProgram -PackageId $Args[0].PackageId -ProgramName $Args[1].Name | ||
+ | |||
+ | Switch ($Args[1].Bitness) | ||
+ | | ||
+ | " | ||
+ | } | ||
+ | |||
+ | |||
+ | If ($Args[1].RunAnotherProgram.Length -gt 0) {$CMProgram.DependentProgram = $Args[0].PackageId + ";;" | ||
+ | |||
+ | #There is no argument for Comment in New-CMProgram so we have to add the Comment with Set-CMProgram. | ||
+ | |||
+ | Set-CMProgram ` | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | |||
+ | cd c: | ||
+ | } | ||
+ | |||
+ | #Main | ||
+ | If ($args.Length -eq 0) {Write-Host "No software given!"; | ||
+ | |||
+ | #Read the package settings from PackageDetails.csv, | ||
+ | #Add Date to the name to randomize the package name. | ||
+ | $PackageDetails = Import-Csv $args[0] | ||
+ | $Date = Get-Date -Format d | ||
+ | $PackageName = $PackageDetails.Name + " | ||
+ | $PaLang = $PackageDetails.Language | ||
+ | $PaManufacturer = $PackageDetails.Manufacturer | ||
+ | $PaPath = $PackageDetails.Path | ||
+ | $PaVersion = $PackageDetails.Version | ||
+ | |||
+ | #Load the module ConfigurationManager and change to the ConfigMgr site. | ||
+ | If(!(Get-Module ConfigurationManager)) {Import-Module " | ||
+ | cd TUY: | ||
+ | |||
+ | #Create the package. | ||
+ | New-CMPackage ` | ||
+ | -Name $PackageName ` | ||
+ | | ||
+ | | ||
+ | -Path $PaPath ` | ||
+ | | ||
+ | |||
+ | #Move the package to the right folder. | ||
+ | $NewCMPackage = Get-CMPackage -Name $PackageName | ||
+ | Move-CMObject -FolderPath " | ||
+ | |||
+ | #Distribute the content if needed. | ||
+ | If($PackageDetails.DistributeContent = " | ||
+ | |||
+ | cd c: | ||
+ | |||
+ | #Import programs from the Programs.csv, | ||
+ | $Programs = Import-Csv $args[1] | ||
+ | ForEach ($Program in $Programs) {CreateProgram $NewCMPackage $Program} | ||
+ | |||
+ | cd TUY: | ||
+ | |||
+ | #Rename the package. | ||
+ | Set-CMPackage ` | ||
+ | | ||
+ | | ||
+ | |||
+ | cd c: | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | FirefoxPackageDetails.csv: | ||
+ | |||
+ | Name, | ||
+ | " | ||
+ | |||
+ | FirefoxPrograms.csv: | ||
+ | |||
+ | Name, | ||
+ | " | ||
+ | " | ||
+ |
ohjeet/skriptit.1286968935.txt.gz · Viimeksi muutettu: 2014/11/20 15:01 (ulkoinen muokkaus)