/build/static/layout/Breadcrumb_cap_w.png

Kscript evaluation of %PUBLIC% environment variable

OK, here's a really weird one: Windows 7 has an environment variable %PUBLIC% that evaluates to C:\Users\Public. (Why do I care? because the Windows 7 "all users" desktop is %PUBLIC%\Desktop, where I want to put a shortcut.)

In a test Kscript, this step in On Success:
Launch "$(KBOX_SYS_DIR)\cmd.exe" with params "/c echo PUBLIC is: %PUBLIC%"
writes to the output log:
PUBLIC is: C:\Users\Public
So far, so good.

In another Kscript, these steps:
Verify
Verify that the file "%PUBLIC%\Desktop\someLink.lnk" exists.
Remediation:
Launch "$(KBOX_SYS_DIR)\cmd.exe" with params "/c if exist "%PUBLIC%\Desktop\*.*" run-a-program "%PUBLIC%""
write to the activity and output logs:
Checking if file exists: C:\ProgramData\Desktop\someLink.lnk
File does not exist: C:\ProgramData\Desktop\someLink.lnk
Launching program: C:\Windows\system32\cmd.exe /c if exist "C:\ProgramData\Desktop\*.*" run-a-program "C:\ProgramData""

Don't get hung up in the details; what I want you to see is that %PUBLIC% evaluated to C:\Users\Public in the test script (as expected), but it evaluated to C:\ProgramData in the other script. Both scripts are set to Run As Local System, and both Allow Run While Logged Off. I tried moving the steps among the Verify, Remediation, and Success sections, but it made no difference.

Now you may say, the Kscript steps "Verify a file exists" and "Launch a program" do not support the use of Windows environment variables. (Yes, that's what the documentation says, but in my experience they do. Still, it doesn't matter:) But in that last "Launch a program" step, I'm not asking the Kscript to evaluate %PUBLIC%; I'm asking cmd.exe to evaluate that variable, just like I did in the test script!

Anybody have any ideas why this environment variable evaluates incorrectly in the second script? Have I found a bug? Is there a workaround, without hard-coding C:\Users\Public? Sande

0 Comments   [ + ] Show comments

Answers (3)

Posted by: airwolf 13 years ago
Red Belt
0
You sure there aren't typos? Can you give us a screenshot of the task?
Posted by: snissen 13 years ago
Fourth Degree Green Belt
0
Worse and worse, in terms of predictability:

I noticed in the second script that I was using an earlier task set to "On Failure: Break", when I really wanted to Continue.

When I changed that earlier task to "On Failure: Continue", then this later task that uses %PUBLIC% began to evaluate correctly!

Moral of the story: In any Kscript task that uses %PUBLIC%, add a step to echo %PUBLIC% to the logs, so you can see if it evaluated correctly or not.

Possible moral of the story: Don't use Windows environment variables after "On Failure: Break".

I hit glitches like this at least once a week. If it weren't for these glitches, I'd like the KBOX 1000 just fine.
Posted by: airwolf 13 years ago
Red Belt
0
It's not a glitch when KACE tells you it's unsupported. I'm glad you figured this out though; it could come in handy for someone later.
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ