Environmental Variables when running MS vs manually

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Environmental Variables when running MS vs manually

Post by Grovkillen » Tue Aug 27, 2024 11:56 am

Save this and run it using F8 (step by step):

Code: Select all


Let>OUTPUT_file=%SCRIPT_DIR%\env.txt
Let>BATCH_file=%SCRIPT_DIR%\env.bat
Let>BATCH_code=set > "%OUTPUT_file%"
DeleteFile>BATCH_file
DeleteFile>OUTPUT_file
WriteLn>BATCH_file,,BATCH_code
ExecuteFile>%BATCH_file%
After running it, copy the contents of the env.txt file to (as an example) https://www.diffchecker.com/text-compare/

Now run the env.bat file manually by clicking on it in the Windows Explorer. Copy the contents to the second field and do the compare.

I have these differences:

Code: Select all

Running as "myself":
CommonProgramFiles=C:\Program Files\Common Files
PROCESSOR_ARCHITECTURE=AMD64
ProgramFiles=C:\Program Files

Macro Scheduler:
CommonProgramFiles=C:\Program Files (x86)\Common Files
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
ProgramFiles=C:\Program Files (x86)
I have found that sometimes the expected output differ when running cmd using the "Run>" command. Could these differences be a result of the env being different?
Last edited by Grovkillen on Tue Aug 27, 2024 12:22 pm, edited 1 time in total.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Environmental Variables when running MS vs manually

Post by Grovkillen » Tue Aug 27, 2024 12:10 pm

Yes it does make a difference. I have a PowerShell script that uses a library, this library is 64-bit only I just found out. In order to get this to run at 64-bit I cannot rely on the good'ol:

Code: Select all

Let>PS_SYNTAX=Get-Date <---- this is just an example to show how I'm doing the PS invoke from CMD
Let>PS_PATH=cd "C:\Windows\System32\WindowsPowerShell\v1.0\" & chcp 65001 & powershell.exe
Run>cmd /c %PS_PATH% -Command " & {%PS_SYNTAX%}"

Instead I need to save the code to an .ps1 file and run it using this:

Code: Select all

Run>C:\Windows\SysNative\WindowsPowerShell\v1.0\powershell.exe -File "c:\path\to\run_as_64bit.ps1"
The downside is that I cannot use RP_CAPTURESTDOUT=1

EDIT: Let>RP_WIN64PROCESS=1 Wasn't helpful in my specific case, but probably in most normal cases!
Last edited by Grovkillen on Tue Aug 27, 2024 12:37 pm, edited 1 time in total.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Environmental Variables when running MS vs manually

Post by Grovkillen » Tue Aug 27, 2024 12:28 pm

Just a though, I'd be very happy if MS could have a way of simply checking Environmental Variables using a:

Code: Select all

EnvVarRead>NAME_OF_VARIABLE,VALUE_OF_VARIABLE,RESULT
If no variable found the RESULT=1 else RESULT=0

And perhaps a write/append

Code: Select all

EnvVarWrite>NAME_OF_VARIABLE,VALUE_OF_VARIABLE,RESULT
EnvVarAppend>NAME_OF_VARIABLE,APPEND_VALUE_OF_VARIABLE,RESULT
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Environmental Variables when running MS vs manually

Post by Grovkillen » Sat Oct 19, 2024 7:35 am

Bump
Let>ME=%Script%

Running: 15.0.27
version history

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts