Run caspol from within vbscript
I would like to call caspol from within a script inside a custom action in msi (setup project). I would prefer the standard msi for ClickOnce because with the standard msi I can install the drivers and associate the filetypes with our application, whereas with ClickOnce I cannot.
When I execute the caspol command from the command line it succeeds, but from within the vbscript it always fails with the error "Fehler: Unbekannte Mitgliedschaftsbedingung - -url .." which translates to "Error: Unknown membership condition: -url". To further clarify: copying and pasting the generated command works fine on the command line directly on the local disk of the virtual machine, as a local administrator, as part of a workgroup.
I have two ideas: 1. I'm not the king of vbscript, so maybe I missed the quotes or made some other kind of syntax error. 2. Caspol recognizes that I am running it from a script and stops with an intentionally meaningless error.
Personally, I think this is just a dumb syntax error.
Here's my script:
set sh = CreateObject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
dim command
dim location
dim retVal
location = fso.GetFile(Wscript.ScriptFullName).ParentFolder
'%windir%\microsoft.net\framework\v2.0.50727\caspol.exe -pp off -m -addgroup 1 –url file://COMPUTER/SHARE/* FullTrust -name sbw2
command = fso.GetSpecialFolder(0) & "\microsoft.net\framework\v2.0.50727\caspol.exe -pp off -m -ag 1 –url file://"
for each s in Split(location, "\")
if Len(s) > 0 then
command = command & s & "/"
end if
next
command = command & "* FullTrust -name sbw2"
'DEBUG
'command = fso.GetSpecialFolder(0) & "\microsoft.net\framework\v2.0.50727\caspol.exe -m -ag 1 –url file://mjlaptop/sbw2/* FullTrust"
Wscript.StdOut.WriteLine VbClrf
Wscript.StdOut.WriteLine command
Wscript.StdOut.WriteLine VbClrf
Set output = sh.Exec(command)
dim text
while Not output.StdOut.AtEndOfStream
text = text & output.StdOut.Read(1)
Wend
Wscript.StdOut.WriteLine text
Thanks in advance,
Matt
source to share
Copy and paste from your answer to my code:
"C:\WINDOWS\microsoft.net\framework\v2.0.50727\caspol.exe -pp off -m -ag 1 -url "file://mjlaptop/sbw2/*" FullTrust -name sbw2
\\mjlaptop\sbw2\setpolicy.vbs(32, 1) WshShell.Exec: Das System kann die angegebene Datei nicht finden.
Missing quote. And now by adding the closing quotation mark as I assumed you intended:
"C:\WINDOWS\microsoft.net\framework\v2.0.50727\caspol.exe" -pp off -m -ag 1 -url "file://mjlaptop/sbw2/*" FullTrust -name sbw2
Microsoft (R) .NET Framework CasPol 2.0.50727.42
Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.
Fehler: Unbekannte Mitgliedschaftsbedingung - -url..
This is the error mentioned in my original post. You're right: the command is valid. That the command is valid is not a problem. I can copy and paste the bloody echo into the command window and it succeeds. I can stick with as many quotes there as you like, and I believe he will still complain about an "unknown membership condition".
I'll try to make my comments in the comments.
source to share
"C: \ WINDOWS \ microsoft.net \ framework \ v \ caspol" -pp off -m -ag 1 -url "file: // mjlaptop / sbw2 / *" FullTrust -name sbw2
Microsoft (R) .NET Framework CasPol 2.0.50727.42 Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.
Fehler: Unbekannte Mitgliedschaftsbedingung - -url ..
using v instead of the entire filename allows the code to look for caspol in each version folder.
source to share