% temp%, etc.no funciona

I have the below that is used as a batch file that launches powershell (too long to go over but it is used in another script).

Anyway, I noticed the %systemroot%\temp and %systemroot% does not work.

¿Alguna idea de cómo puedo solucionar esto?

%systemroot%\system32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Unrestricted -File %SystemRoot%\TEMP\ROFS\testing_script_log.ps1

Gracias,

preguntado el 08 de noviembre de 11 a las 13:11

Done on my system works great. Which is the error you have? -

your right Christian....my stupidity...the path is incorrect!! Would have worked in the end! -

3 Respuestas

If you are executing that line from PowerShell rather than from CMD, you can use the PowerShell environment variable syntax:

PS C:\> & "$env:SystemRoot\System32\WindowsPowerShell\v1.0\powershell.exe"

respondido 08 nov., 11:18

I wanted to know this as well - so thanks for answering it. The actual fault was the path was incorrect - this is fixed now but good to know the above. - lara400

I'm a huge noob. Why do you need the "&" at the beginning of the line? - YasharBahman

You can use [Environment]::ExpandEnvironmentVariables to expand environment variables within a string the old-fashioned way.

$s = '%systemroot%\temp'
[Environment]::ExpandEnvironmentVariables($s)

respondido 08 nov., 11:19

Useful with PowerShell 2.0 (Windows 2008) where "$env.SYSTEMROOT" does not work - qué

en realidad lo es $s = [Environment]::ExpandEnvironmentVariables($s) - uceumern

Successfully verified with below code C#.

//file location - User Variables string fileLocation = Environment.GetEnvironmentVariable("AZURE_FILE_PATH", EnvironmentVariableTarget.User); //file location - System Variables string fileLocation = Environment.GetEnvironmentVariable("AZURE_FILE_PATH", EnvironmentVariableTarget.Machine);

On Powershell script

& "D:\Visual_Studio_Workspace\AzureUpload\AzureUpload\bin\Debug\AzureUpload.exe"

AzureUpload.exe -- contain the above code C# code as Console application (Visual_Studio_Workspace\AzureUpload\AzureUpload\bin\Debug{.exe file location})

respondido 16 mar '17, 10:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.