1

I am using MS Server 2012 R2 64bit with Active Directory installed. I want to execute a few batch scripts when the user logs into a computer. These scripts use the "reg add/query" commands to check if a registry key exists and if it doesn't it will create it and set a value to the new key. The problem I'm having is that it seems that every time the scripts run when a user executes, the scripts attempt to execute the reg add/query commands and it gets an "access denied" message. Here is a sample of my batch script:

reg query HKCU\Software\myownkey >null 2>&1

if %ERRORLEVEL%% NEQ 0 (
   echo myownkey doesn't exist. Must create it.
   reg add HKCU\Software /v myownkey /t REG_DWORD /f /d 1 >null 2>&1
)

PAUSE

When the user logs into the machine, the script is executed and then it pauses so I can see if the script executed properly or not. All I see is that it prints "Access Denied" every time it attempts to query/add the registry.

Any one knows how to solve this problem? Am I better off using powershell scripts instead and won't run into this problem?

Thank you in advanced!

2
  • Could you log in as one of the problem users and just double check the permissions on the HKCU\Software key?
    – Neil
    Dec 29, 2015 at 5:18
  • Yes, I can log in as a domain user and each user does have access to the scripts and can execute them properly and it does work. That's what I don't understand as to why the logon GPO doesn't work. When using the logon GPO, the script is executed but I get access denied when attempting to read/write to the registry using the reg query/add command.
    – Carl Rod
    Dec 29, 2015 at 16:17

1 Answer 1

0

Do not double L in NUL:

reg query HKCU\Software\myownkey >NUL 2>&1

>null attempts to redirect command output to a file named null in the current directory which is supposedly C:\Windows or C:\Windows\system32.

nul

The null device is a special file that discards all data written to it, but reports that the write operation succeeded.

It is often used to hide the output (or error output) of a command.

e.g.

SomeCommand >nul

Nul provides no data to any process that reads from it (yielding EOF immediately)

For more examples see the redirection page.

1
  • You sir are amazing! Thank you so much for catching that error in my code. I was using null instead of nul because I was so used to using null in Linux that I just thought it was the same in Windows. Anyhow, I am very happy that you found a solution to my problem. Thank you again!
    – Carl Rod
    Dec 31, 2015 at 19:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .