Seite 1 von 1

[Frage] OPSI Script VBS ausführen

Verfasst: 26 Jun 2017, 15:08
von NeZoX
Hallo zusammen,

leider ist es mir nicht gelungen einen VBS Script in OPSI durchzuführen.
Ich habe viele sachen ausprobiert doch leider kam ich nicht zum ergebnis.

Setup.opsiscript

Code: Alles auswählen

Message = Bitte warten, das Produkt wird installiert
setLogLevel = 3
ExitOnError = false
ScriptErrorMessages = on
TraceMode = off
StayOnTop = false
 
[Actions]
requiredWinstVersion >= "4.11"

DefVar $ProductId$
DefVar $ProductName$
DefVar $ExitCode$
DefVar $LogDir$

Set $LogDir$ = "%SystemDrive%\tmp" + $ProductID$

; ----------------------------------------------------------------
; - Please edit the following values                             -
; ----------------------------------------------------------------
Set $ProductId$       = "Script"
; ----------------------------------------------------------------

ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$

ExecWith_VBS "%SystemDrive%\Windows\System32\cscript.exe"

[ExecWith_VBS]
1.times do
	"%ScriptPath%\ps_config.vbs"
end
Dies war nur eine Variation welche ich ausprobiert habe.


script.vbs

Code: Alles auswählen

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1
Const ForWriting = 2
 
' Datei öffnen und Text einlesen und schließen
Set objFile = objFSO.OpenTextFile("C:\ProgramData\PROGRAM\SystemConfiguration.xml", ForReading)
strText = objFile.ReadAll
objFile.Close
 
' Änderungen am Inhalt
strNewText = Replace(strText, """", "'")
strNewText = Replace(strNewText, "NAME", "IP")
 
' Neue Datei erstellen mit neuen Inhalten füllen
set resultFile = objFSO.CreateTextFile("C:\ProgramData\PROGRAM\SystemConfiguration.xml", true)
resultFile.WriteLine strNewText
resultFile.Close
			
if InStr(1, strNewText, "IP", 1) > 0 Then 
MsgBox "Erfolgreich",VBOKOnly,""
else
MsgBox "Fehlgeschlagen",VBOKOnly,""
end if
Das Script soll die IP mit dem Namen austauschen.

Hat jemand eine Idee wie ich das Script zum laufen bekomme.

VG
NeZoX

Re: [Frage] OPSI Script VBS ausführen

Verfasst: 26 Jun 2017, 18:45
von SisterOfMercy
Why not make a winbatch that runs cscript.exe (that executes your script of course)?

Re: [Frage] OPSI Script VBS ausführen

Verfasst: 27 Jun 2017, 08:03
von NeZoX
How can i do that?
Someting like this :

Code: Alles auswählen

ExecWith_CMD "%SystemDrive%\Windows\System32\cmd.exe"

[ExecWith_VBS]
1.times do
   "%ScriptPath%\run_vbs.cmd"
end

Re: [Frage] OPSI Script VBS ausführen

Verfasst: 27 Jun 2017, 11:53
von SisterOfMercy
You're making it too difficult.

Code: Alles auswählen

[Actions]
Winbatch_install_vbs /SysNative

[Winbatch_install_vbs]
"%SystemRoot%\system32\cscript.exe" "%ScriptPath%\script.vbs"
Now I think of it, just running run_vbs.cmd in a winbatch section may work as well. But it's probably more 'correct' to use cscript.

Re: [Frage] OPSI Script VBS ausführen

Verfasst: 27 Jun 2017, 12:57
von NeZoX
Hello, this dosnt work.
Here the Log:

Code: Alles auswählen

[1] [Jun 27 12:54:08:207] --
[1] [Jun 27 12:54:08:208] --
[1] [Jun 27 12:54:08:208] c:\opsi.org\log\opsi-script-part-Bf54Fu94.log
[1] [Jun 27 12:54:08:210] opsi-script 4.11.6.6 started at 27.06.2017 12:54:06
[1] [Jun 27 12:54:08:211] opsi-script log file with encoding utf8
[6] [Jun 27 12:54:08:212] Using Depot path:  z:\
[1] [Jun 27 12:54:08:216] 
[1] [Jun 27 12:54:08:217] ============ Version 4.11.6.6 script "C:\Users\USER\Desktop\Script\CLIENT_DATA\setup.opsiscript"
[1] [Jun 27 12:54:08:218]              used script encoding: cp1252
[1] [Jun 27 12:54:08:218]              used system encoding: cp1252
[1] [Jun 27 12:54:08:219]              start: 2017-06-27  12:54:08 
[1] [Jun 27 12:54:08:220]              on client named    "COMPUTER"
[1] [Jun 27 12:54:08:222]              loggedin user    "USER"
[1] [Jun 27 12:54:08:223]              opsi-script running as    "USER"
[1] [Jun 27 12:54:08:225]              opsi-script running with admin privileges
[1] [Jun 27 12:54:08:226]              opsi-script running in standard script mode
[1] [Jun 27 12:54:08:227] executing: "C:\Program Files (x86)\opsi.org\opsi-client-agent\opsi-winst\winst32.exe"
[1] [Jun 27 12:54:08:229] system infos:
[1] [Jun 27 12:54:08:238] XX-XX-XX-32-23-45  -  PC hardware address
[1] [Jun 27 12:54:08:240] COMPUTER -  IP name 
[1] [Jun 27 12:54:08:241] 10.0.1.2  -  IP address
[1] [Jun 27 12:54:08:243] DEU  -  System default locale 
[1] [Jun 27 12:54:08:245] MS Windows 6.1 64 Bit, Edition: PRODUCT_PROFESSIONAL
[1] [Jun 27 12:54:08:246] 
[6] [Jun 27 12:54:08:249] Registry key [HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion]  opened
[6] [Jun 27 12:54:08:251] Key closed
[6] [Jun 27 12:54:08:385] opsi-script has version  4.11.6.6, required is : >= 4.11
[5] [Jun 27 12:54:08:387] Set  $LogDir$ = "C:\tmp" + $ProductID$
[6] [Jun 27 12:54:08:388]   The value of the variable "$LogDir$" is now: "C:\tmp"
[5] [Jun 27 12:54:08:390] Set  $ProductId$       = "Script"
[6] [Jun 27 12:54:08:392]   The value of the variable "$ProductId$" is now: "Script"
[1] [Jun 27 12:54:08:397] ___________________
[1] [Jun 27 12:54:08:399] script finished
[1] [Jun 27 12:54:08:400] 0 errors
[1] [Jun 27 12:54:08:401] 0 warnings
[1] [Jun 27 12:54:08:403] 
[1] [Jun 27 12:54:08:404] 
Seems like the script skip the [Actions] sektion.

setup.opsiscript

Code: Alles auswählen

Message = Bitte warten, das Produkt wird installiert
setLogLevel = 3
ExitOnError = false
ScriptErrorMessages = on
TraceMode = off
StayOnTop = false
 
[Actions]
requiredWinstVersion >= "4.11"

DefVar $ProductId$
DefVar $ProductName$
DefVar $ExitCode$
DefVar $LogDir$

Set $LogDir$ = "%SystemDrive%\tmp" + $ProductID$

; ----------------------------------------------------------------
; - Please edit the following values                             -
; ----------------------------------------------------------------
Set $ProductId$       = "Script"
; ----------------------------------------------------------------

ShowBitmap "%ScriptPath%\" + $ProductId$ + ".png" $ProductId$

[Actions]
WinBatch_install_vbs /SysNative

[WinBatch_install_vbs]
"%SystemRoot%\system32\cscript.exe" "%ScriptPath%\config.vbs"

Re: [Frage] OPSI Script VBS ausführen

Verfasst: 27 Jun 2017, 13:41
von SisterOfMercy
You can only have one [actions] header.

https://download.uib.de/opsi_stable/doc ... im-section
(here they talk about Action instead of Actions, which I think is a spelling error)

BTW, it looks like you want to edit a file with the VBS script. OPSI can do stuff like this too. But first get your basics working.