none
Updating Registry Values in Server 2008 R2 using task scheduler

    Question

  • Hello,

    I have some custom software that was written to control access to certain floors of an elevator system based of a set of registry values.  Per the company that wrote this software, the only way I can change how it acts on business holidays is run an exported .reg file.  And this works if I run these files manually, or if I write a .bat file in order to run them together.  But if I try to run that .bat from task scheduler it says that "The operation completed successfully. (0x0)" but the registry has not been changed.  And I have configured the task to run as the system Administrator account.

    As an example this is my .bat file:

    @echo off 
    regedit /s "Testing off.reg" 
    cls 

    And my .reg file:

    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\Testing]
    "Testing String"="1100,1100,1100,1100,1100,1100"

    I have noticed that when I run the .bat file manually it does prompt me to accept the security risks, but it does not do this when I run it via task scheduler.  So I have to assume that this is a security issue with running it as a .bat file.

    Now I know this could possibly be done with powerhshell or VBscrits, but I am not well enough versed in writing those.  And if I could get help writing one of these scripts I could try one of them.

    So if someone could please help me with this, it would be great


    Tuesday, July 30, 2013 4:29 AM

Answers

  • Here is a VB if you like.

    '=============================

    Const HKEY_CURRENT_USER = &H80000001 strComputer = "." ' Replace <computername> with the computer name that your want to modify registry on or . for ' local machine Set RegistryObject=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") strKeyPath = "Software\Testing"

    strValueName = "Testing String" strValue = "1100,1100,1100,1100,1100,1100" RegistryObject.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue


    '=============================


    Regards, Vik Singh "If this thread answered your question, please click on "Mark as Answer"

    • Marked as answer by Les Holdeman Tuesday, July 30, 2013 6:10 AM
    Tuesday, July 30, 2013 5:19 AM

All replies

  • Go into the batch file and explicitily set Full Control on the file for everyone (test) or for Administrator.

    See if that works.


    Regards, Vik Singh "If this thread answered your question, please click on "Mark as Answer"

    Tuesday, July 30, 2013 4:45 AM
  • Permissions on all Groups or user names was already set to Full Control on the .bat file.  Also checked the .reg file and permissions are the same.  Still not working.
    Tuesday, July 30, 2013 4:59 AM
  • Here is a VB if you like.

    '=============================

    Const HKEY_CURRENT_USER = &H80000001 strComputer = "." ' Replace <computername> with the computer name that your want to modify registry on or . for ' local machine Set RegistryObject=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") strKeyPath = "Software\Testing"

    strValueName = "Testing String" strValue = "1100,1100,1100,1100,1100,1100" RegistryObject.SetStringValue HKEY_CURRENT_USER, strKeyPath, strValueName, strValue


    '=============================


    Regards, Vik Singh "If this thread answered your question, please click on "Mark as Answer"

    • Marked as answer by Les Holdeman Tuesday, July 30, 2013 6:10 AM
    Tuesday, July 30, 2013 5:19 AM
  • Thank you so much for the assistance.  Creating the VB script and running that through Task Scheduler has allowed me to make the registry changes at a certain time on certain days.  And now this will let me pre-schedule the holidays so the customer doesn't have to due it manually every time.
    Tuesday, July 30, 2013 6:12 AM
  • Ok, so I tried changing the VB script from what you wrote to the actual key values and it doesn't work now.  Maybe you can help me with some debugging?

            Const HKEY_LOCAL_MACHINE = &H80000002
    
            strComputer = "."       ' Replace <computername> with the computer name that your want to modify registry on or . for 
    
            ' local machine
    
            RegistryObject = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    
            strKeyPath = "SOFTWARE\Wow6432Node\SAR\KONEWPConnector"
    
            strValueName = "kgc_dop_global_default_mask_connected"
    
            strValue = "1111,1111,1111,1111,1111,1111,1100,1111,1111,1111,1111,1111,1111,1111"
    
            RegistryObject.SetStringValue(HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue)


    Tuesday, July 30, 2013 6:52 AM
  • OK, never mind.  it was a permissions thing on that branch of the Registry tree.  Only the CREATOR OWNER had full control of that key.  Once I gave system and users full control it worked like a champ again.
    • Edited by Les Holdeman Tuesday, July 30, 2013 7:01 AM miss spelling
    Tuesday, July 30, 2013 6:58 AM
  • ok, But some typos also in the one you pasted. You missed the "SET" in the 3rd line. And typo on the last. Should be
     Const HKEY_LOCAL_MACHINE = &H80000002
    
            strComputer = "."       ' Replace <computername> with the computer name that your want to modify registry on or . for 
    
            ' local machine
    
            Set RegistryObject = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
    
            strKeyPath = "SOFTWARE\Wow6432Node\SAR\KONEWPConnector"
    
            strValueName = "kgc_dop_global_default_mask_connected"
    
            strValue = "1111,1111,1111,1111,1111,1111,1100,1111,1111,1111,1111,1111,1111,1111"
    
            RegistryObject.SetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue


    Regards, Vik Singh "If this thread answered your question, please click on "Mark as Answer"

    Tuesday, July 30, 2013 7:00 AM
  • Don't know why, but Visual Studio 2010 Express removes the Set on the 3rd line every time I type it in and automatically adds the () on the last line if I delete them.  But after I published them and installed them as apps they work just fine so I am not going to question why it is changing the syntax on me.
    Tuesday, July 30, 2013 7:11 AM