0

I'm doing a project with not enough time to rewrite what is written in HTA. I need to call a HTA using cmd.exe /C (so it closes the window after it formulates, generating a flashing hta box). I am able to do this in an invoke-expression fashion, but I'm trying to get it as a start-job with a mixture of variables.

$RunHTA = { 
param(
[string]$FP,  ### filepath to hta
[string]$output)  ### output
Invoke-Expression -command 'cmd.exe /C $FP /H:`"$output`"'  ### this line works alone. the /H is the save report feature and the double quotes are needed by the hta
}

$fp="C:\Path\To\HTA\file.hta"
$output = "C:\Output\path"
$j = Start-job $RunHTA -ArgumentList $FP,$output
$j | Receive-job

The filename, directory name, or volume label syntax is incorrect.
+ CategoryInfo          : NotSpecified: (The filename, d...x is incorrect.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

I've done some testing and the variables are getting passed through correctly. Using returns to see the full variables.

Seems simple and probably something that should work without hassle.

Any ideas?

  • The Solution: $RunHTA = { param( [string]$FP, ### filepath to hta [string]$output) ### output Invoke-Expression -command "cmd.exe /C $FP /H:`"`"`"$output`"`"`"" ### this line works alone. the /H is the save report feature and the double quotes are needed by the hta } [http://stackoverflow.com/questions/6714165/powershell-stripping-double-quotes-from-command-line-arguments][1] [1]: http://stackoverflow.com/questions/6714165/powershell-stripping-double-quotes-from-command-line-arguments – user1981178 Jan 15 '13 at 21:27

1 Answers1

0

Try wrapping command in double quotes instead

Invoke-Expression -command "cmd /c $FP /H:`"$output`""
jbockle
  • 633
  • 5
  • 11
  • The problem with the doublequotes is that my escaped doublequotes get removed, which is needed for the HTA to function correctly. – user1981178 Jan 15 '13 at 19:45