[gelöst] PowerShell-Version abfragen: "Zugriff verweigert"

Antworten
holgerv
Beiträge: 288
Registriert: 20 Aug 2012, 09:35

[gelöst] PowerShell-Version abfragen: "Zugriff verweigert"

Beitrag von holgerv »

Hallo,

ich möchte in einem opsi-Winst-Skript abfragen, ob PowerShell 4.0 installiert ist:

Code: Alles auswählen

[Actions]
comment getRegistryStringValueSysNative("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3]")
comment getRegistryStringValueSysNative("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine]")
comment getRegistryStringValueSysNative("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine] PowerShellVersion")
führt zu folgendem Output:

Code: Alles auswählen

[1] [Aug 05 14:08:29:399] --
[1] [Aug 05 14:08:29:400] --
[1] [Aug 05 14:08:29:402] c:\opsi.org\log\opsi-script-part-Gu87Mn79.log
[1] [Aug 05 14:08:29:403] opsi-winst 4.11.4.21 started at 05.08.2015 13:21:40
[1] [Aug 05 14:08:29:404] 
[1] [Aug 05 14:08:29:405] ============ Version 4.11.4.21 script "C:\Users\[...]\Desktop\test.ins"
[1] [Aug 05 14:08:29:406]              used script encoding: cp1252
[1] [Aug 05 14:08:29:407]              used system encoding: cp1252
[1] [Aug 05 14:08:29:408]              start: 2015-08-05  14:08:29 
[1] [Aug 05 14:08:29:408]              on client named    "[...]"
[1] [Aug 05 14:08:29:409]              loggedin user    ""
[1] [Aug 05 14:08:29:411]              winst running as    "[...]"
[1] [Aug 05 14:08:29:411]              winst running with admin privileges
[1] [Aug 05 14:08:29:411]              winst running in standard script mode
[1] [Aug 05 14:08:29:412] executing: "C:\Program Files (x86)\opsi.org\opsi-client-agent\opsi-winst\winst32.exe"
[1] [Aug 05 14:08:29:414] system infos:
[1] [Aug 05 14:08:29:415] [...]  -  PC hardware address
[1] [Aug 05 14:08:29:417] [...]  -  IP name 
[1] [Aug 05 14:08:29:418] [...]  -  IP address
[1] [Aug 05 14:08:29:421] DEU  -  System default locale 
[1] [Aug 05 14:08:29:423] MS Windows 6.1 64 Bit
[1] [Aug 05 14:08:29:424] 
[6] [Aug 05 14:08:29:427] Registry key [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion]  opened
[6] [Aug 05 14:08:29:428] Key closed
[6] [Aug 05 14:08:29:483]   Registry key [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3]  opened
[6] [Aug 05 14:08:29:484]   Key closed
[5] [Aug 05 14:08:29:486] comment: 
[6] [Aug 05 14:08:29:489]   Info: Registry key [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine]   could not be opened by RegOpenKeyEx,  Errorno 5 "Zugriff verweigert<"
[5] [Aug 05 14:08:29:490] comment: 
[6] [Aug 05 14:08:29:493]   Info: Registry key [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine]   could not be opened by RegOpenKeyEx,  Errorno 5 "Zugriff verweigert<"
[5] [Aug 05 14:08:29:495] comment: 
[1] [Aug 05 14:08:29:503] ___________________
[1] [Aug 05 14:08:29:504] script finished
[1] [Aug 05 14:08:29:506] 0 errors
[1] [Aug 05 14:08:29:508] 0 warnings
[1] [Aug 05 14:08:29:509] 
[1] [Aug 05 14:08:29:511] 
Mit reg.exe (als gleicher Benutzer ausgeführt) kann ich den Wert aber auslesen:

Code: Alles auswählen

C:\>reg.exe query HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine /v PowerShellVersion

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine
    PowerShellVersion    REG_SZ    4.0
Kann sich jemand erklären, was ich falsch mache?

Vielen Dank


Holger
Zuletzt geändert von holgerv am 11 Aug 2015, 11:51, insgesamt 1-mal geändert.
Benutzeravatar
SisterOfMercy
Beiträge: 1556
Registriert: 22 Jun 2012, 19:18

Re: PowerShell-Version abfragen: "Zugriff verweigert"

Beitrag von SisterOfMercy »

Maybe try it with explicit 32/64-bit command?

Code: Alles auswählen

[Actions]
comment getRegistryStringValue32("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3]")
comment getRegistryStringValue32("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine]")
comment getRegistryStringValue32("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine] PowerShellVersion")
comment getRegistryStringValue64("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3]")
comment getRegistryStringValue64("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine]")
comment getRegistryStringValue64("[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine] PowerShellVersion")
Bitte schreiben Sie Deutsch, when I'm responding in the German-speaking part of the forum!
holgerv
Beiträge: 288
Registriert: 20 Aug 2012, 09:35

Re: PowerShell-Version abfragen: "Zugriff verweigert"

Beitrag von holgerv »

SisterOfMercy hat geschrieben:Maybe try it with explicit 32/64-bit command?
Das hat leider nicht geholfen. Dein Code führt zu folgendem Ergebnis:

Code: Alles auswählen

[1] [Aug 07 15:25:21:113] --
[1] [Aug 07 15:25:21:113] --
[1] [Aug 07 15:25:21:114] c:\opsi.org\log\opsi-script-part-Tt92Gc28.log
[1] [Aug 07 15:25:21:116] opsi-winst 4.11.4.21 started at 07.08.2015 15:25:08
[1] [Aug 07 15:25:21:118] 
[1] [Aug 07 15:25:21:118] ============ Version 4.11.4.21 script "C:\Users\[...]\Desktop\test2.ins"
[1] [Aug 07 15:25:21:120]              used script encoding: cp1252
[1] [Aug 07 15:25:21:120]              used system encoding: cp1252
[1] [Aug 07 15:25:21:120]              start: 2015-08-07  15:25:21 
[1] [Aug 07 15:25:21:121]              on client named    "[...]"
[1] [Aug 07 15:25:21:122]              loggedin user    ""
[1] [Aug 07 15:25:21:123]              winst running as    "[...]"
[1] [Aug 07 15:25:21:124]              winst running with admin privileges
[1] [Aug 07 15:25:21:125]              winst running in standard script mode
[1] [Aug 07 15:25:21:126] executing: "C:\Program Files (x86)\opsi.org\opsi-client-agent\opsi-winst\winst32.exe"
[1] [Aug 07 15:25:21:126] system infos:
[1] [Aug 07 15:25:21:224] [...]  -  PC hardware address
[1] [Aug 07 15:25:21:227] [...]  -  IP name 
[1] [Aug 07 15:25:21:230] [...]  -  IP address
[1] [Aug 07 15:25:21:233] DEU  -  System default locale 
[1] [Aug 07 15:25:21:235] MS Windows 6.1 64 Bit
[1] [Aug 07 15:25:21:236] 
[6] [Aug 07 15:25:21:238] Registry key [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion]  opened
[6] [Aug 07 15:25:21:240] Key closed
[6] [Aug 07 15:25:21:292]   Registry key [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3]  opened
[6] [Aug 07 15:25:21:293]   Variable ""  not found. Code: 2
[6] [Aug 07 15:25:21:295]   Variable ""  not found. Code: 2
[6] [Aug 07 15:25:21:297]   Key closed
[5] [Aug 07 15:25:21:299] comment: 
[6] [Aug 07 15:25:21:334]   Info: Registry key [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine]   could not be opened by RegOpenKeyEx,  Errorno 5 "Zugriff verweigert<"
[5] [Aug 07 15:25:21:337] comment: 
[6] [Aug 07 15:25:21:340]   Info: Registry key [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine]   could not be opened by RegOpenKeyEx,  Errorno 5 "Zugriff verweigert<"
[5] [Aug 07 15:25:21:342] comment: 
[6] [Aug 07 15:25:21:343]   Registry key [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3]  opened
[6] [Aug 07 15:25:21:346]   Key closed
[5] [Aug 07 15:25:21:348] comment: 
[6] [Aug 07 15:25:21:349]   Info: Registry key [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine]   could not be opened by RegOpenKeyEx,  Errorno 5 "Zugriff verweigert<"
[5] [Aug 07 15:25:21:350] comment: 
[6] [Aug 07 15:25:21:353]   Info: Registry key [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine]   could not be opened by RegOpenKeyEx,  Errorno 5 "Zugriff verweigert<"
[5] [Aug 07 15:25:21:354] comment: 
[1] [Aug 07 15:25:21:360] ___________________
[1] [Aug 07 15:25:21:361] script finished
[1] [Aug 07 15:25:21:363] 0 errors
[1] [Aug 07 15:25:21:364] 0 warnings
[1] [Aug 07 15:25:21:366] 
[1] [Aug 07 15:25:21:368] 
An Berechtigungen scheint es nicht zu liegen, mit DosInAnIcon und "reg query" komme ich an die Daten heran:

Code: Alles auswählen

[Actions]
DefVar $RegistryKey$
DefVar $RegistryValue$
Set $RegistryKey$ = "HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine"
Set $RegistryValue$ = "PowerShellVersion"

Comment "==> result: " + GetRegistryStringValueSysnative("[" + $RegistryKey$ + "] " + $RegistryValue$)
DosInAnIcon_QueryRegistryValue /winst /sysnative

[DosInAnIcon_QueryRegistryValue]
reg.exe query "$RegistryKey$" /v "$RegistryValue$"

Code: Alles auswählen

[1] [Aug 07 15:35:12:579] --
[1] [Aug 07 15:35:12:580] --
[1] [Aug 07 15:35:12:580] c:\opsi.org\log\opsi-script-part-Ip43Pv55.log
[1] [Aug 07 15:35:12:581] opsi-winst 4.11.4.21 started at 07.08.2015 15:25:08
[1] [Aug 07 15:35:12:584] 
[1] [Aug 07 15:35:12:585] ============ Version 4.11.4.21 script "C:\Users\[...]\Desktop\test.ins"
[1] [Aug 07 15:35:12:585]              used script encoding: cp1252
[1] [Aug 07 15:35:12:586]              used system encoding: cp1252
[1] [Aug 07 15:35:12:587]              start: 2015-08-07  15:35:12 
[1] [Aug 07 15:35:12:588]              on client named    "[...]"
[1] [Aug 07 15:35:12:589]              loggedin user    ""
[1] [Aug 07 15:35:12:592]              winst running as    "[...]"
[1] [Aug 07 15:35:12:594]              winst running with admin privileges
[1] [Aug 07 15:35:12:595]              winst running in standard script mode
[1] [Aug 07 15:35:12:596] executing: "C:\Program Files (x86)\opsi.org\opsi-client-agent\opsi-winst\winst32.exe"
[1] [Aug 07 15:35:12:597] system infos:
[1] [Aug 07 15:35:12:600] [...]  -  PC hardware address
[1] [Aug 07 15:35:12:601] [...]  -  IP name 
[1] [Aug 07 15:35:12:603] [...]  -  IP address
[1] [Aug 07 15:35:12:605] DEU  -  System default locale 
[1] [Aug 07 15:35:12:607] MS Windows 6.1 64 Bit
[1] [Aug 07 15:35:12:609] 
[6] [Aug 07 15:35:12:612] Registry key [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion]  opened
[6] [Aug 07 15:35:12:614] Key closed
[5] [Aug 07 15:35:12:669] Set  $RegistryKey$ = "HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine"
[6] [Aug 07 15:35:12:670]   The value of the variable "$RegistryKey$" is now: "HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine"
[5] [Aug 07 15:35:12:671] Set  $RegistryValue$ = "PowerShellVersion"
[6] [Aug 07 15:35:12:675]   The value of the variable "$RegistryValue$" is now: "PowerShellVersion"
[6] [Aug 07 15:35:12:678]   Info: Registry key [HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine]   could not be opened by RegOpenKeyEx,  Errorno 5 "Zugriff verweigert<"
[5] [Aug 07 15:35:12:680] comment: ==> result: 
[5] [Aug 07 15:35:12:683] 
[5] [Aug 07 15:35:12:685] DosInAnIcon_QueryRegistryValue
[6] [Aug 07 15:35:12:689]   c:\opsi.org\tmp\_winstbat_Sk48Jh03.cmd saved back
[6] [Aug 07 15:35:12:691]   Executing "C:\Windows\\cmd64.exe" /C "c:\opsi.org\tmp\_winstbat_Sk48Jh03.cmd" /
[6] [Aug 07 15:35:12:913]   ExitCode 0
[6] [Aug 07 15:35:12:918]               
[6] [Aug 07 15:35:12:924]               output:
[6] [Aug 07 15:35:12:927]               --------------
[6] [Aug 07 15:35:12:931]               
[6] [Aug 07 15:35:12:934]               C:\Program Files (x86)\opsi.org\opsi-client-agent\opsi-winst>reg.exe query "HKLM\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine" /v "PowerShellVersion" 
[6] [Aug 07 15:35:12:938]               
[6] [Aug 07 15:35:12:943]               HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\3\PowerShellEngine
[6] [Aug 07 15:35:12:946]                   PowerShellVersion    REG_SZ    4.0
[6] [Aug 07 15:35:12:949]               
[6] [Aug 07 15:35:12:954]   
[6] [Aug 07 15:35:12:960]   Delete "c:\opsi.org\tmp\_winstbat_*"
[6] [Aug 07 15:35:12:964]     Search "c:\opsi.org\tmp\"
[1] [Aug 07 15:35:12:974] ___________________
[1] [Aug 07 15:35:12:978] script finished
[1] [Aug 07 15:35:12:982] 0 errors
[1] [Aug 07 15:35:12:985] 0 warnings
[1] [Aug 07 15:35:12:994] 
[1] [Aug 07 15:35:12:998] 
Schönen Gruß


Holger
holgerv
Beiträge: 288
Registriert: 20 Aug 2012, 09:35

Re: PowerShell-Version abfragen: "Zugriff verweigert"

Beitrag von holgerv »

Hallo,

war wohl ein Bug im opsi-winst, der mit http://download.uib.de/opsi4.0/testing/ ... .10-1.opsi behoben ist.

Schönen Gruß


Holger
Antworten