Problem with 2 commands in 1 vbs
I have a little problem with simple vbScript. The script should run 2 actions one after the other.
Option Explicit
Dim WshShell
Dim Yesterday
Dim resultat
Dim commande
Dim Jour
Set WshShell = WScript.CreateObject("WScript.Shell")
Yesterday = DateAdd("d", -2, Date())
resultat = "00001"
resultat = resultat & Right(Year(Yesterday), 2)
Jour = (Datepart("y", Yesterday))
If ((Jour < 100) and (Jour > 9)) Then resultat = resultat & "0" & Jour
If (Jour < 10) Then resultat = resultat & "00" & Jour
If (Jour >= 100) Then resultat = resultat & Jour
resultat = """(&(objectClass=eTGlobalUser)(eTSuspended=0)(eTRoleDN=*)(eTUpdateDate>=" & resultat & "))"""
commande = GetScriptPath() & "PharosGDH.exe /ldapfilter:" & resultat & " /conso"
WshShell.Run commande, 5, true
commande2 = GetScriptPath() & "PharosGDH.exe /all /auditPharos
WshShell.Run commande2, 5, true
WScript.Quit 1
Function GetScriptPath()
GetScriptPath = Left(WScript.ScriptFullName, InStrRev(WScript.ScriptFullName, "\"))
End Function
Can someone tell me what is wrong please?
Sorry there was no declaration in the copy / past and Windows juste shut down silently, after which I see the result is not crazy!
-1
source to share
1 answer
Is this your actual code? It has at least two syntax errors:
First syntax error:
commande2 = GetScriptPath() & "PharosGDH.exe /all /auditPharos
There are no double quotes at the end of the line:
commande2 = GetScriptPath() & "PharosGDH.exe /all /auditPharos"
Second syntax error:
Dim resultat
Dim commande
Dim Jour
The variable "commande2" is used, but not declared. Using:
Dim resultat
Dim commande
Dim commande2
Dim Jour
If that doesn't fix your problem, as others have said, please let us know what the problem is: an error message? Inappropriate behavior?
Second attempt
Perhaps display the commands used before executing them to check that they contain the correct content:
commande = GetScriptPath() & "PharosGDH.exe /ldapfilter:" & resultat & " /conso"
WshShell.Popup commande
WshShell.Run commande1, 5, true
commande2 = GetScriptPath() & "PharosGDH.exe /all /auditPharos"
WshShell.Popup commande
WshShell.Run commande2, 5, true
WScript.Quit 1
+1
source to share