Batch files in DS

Batch files in DS

I'm hoping someone can answer a question for me that has me a little baffled. I have a couple of commands/ batch files that I'm trying to run.

regedit /E "c:\VMPlaybackDevices.txt" "HKEY_CURRENT_USER\Software\Active Voice\TeLANophy\Audio\Playback"

and

POWERCFG /CREATE SCFGreenStar-laptop
POWERCFG /CHANGE SCFGreenStar-laptop /monitor-timeout-ac 15
POWERCFG /CHANGE SCFGreenStar-laptop /disk-timeout-ac 5
POWERCFG /CHANGE SCFGreenStar-laptop /standby-timeout-ac 30
POWERCFG /CHANGE SCFGreenStar-laptop /monitor-timeout-dc 3
POWERCFG /CHANGE SCFGreenStar-laptop /disk-timeout-dc 5
POWERCFG /CHANGE SCFGreenStar-laptop /standby-timeout-dc 15
POWERCFG /HIBERNATE ON
POWERCFG /GLOBALPOWERFLAG ON /OPTION BATTERYICON
POWERCFG /GLOBALPOWERFLAG ON /OPTION RESUMEPASSWORD
POWERCFG /GLOBALPOWERFLAG ON /OPTION VIDEODIM
POWERCFG /BATTERYALARM LOW /ACTIVATE ON /LEVEL 10 /TEXT on
POWERCFG /BATTERYALARM CRITICAL /ACTIVATE ON /LEVEL 3 /TEXT on /ACTION hibernate /FORCEACTION on
POWERCFG /SETACTIVE SCFGreenStar-laptop

When I run either of these, either in the DS job directly or by launching a locally-stored batch file from DS, I get different results than if I launch them manually. With the first script, I don't get the same registry values and with the second, it doesn't actually change the name in the drop-down box in the Power Options Properties dialog box even though the settings are applied. If I run either of these manually, they both work like a charm. I've tried running them with the default system account and with a local admin account. Nothing works. Can someone explain why, and if possible, how to get around it?

Thanks,
John

Perhaps some version information?

vortex0007's picture

What build of DS are you running?

Version

Vortex, thanks for responding. We are running DS version 6.8 (Build 206).

The problem is your

The problem is your changing the registry for HKEY_CURRENT_USER. DS is not running as the same user you are logged in as.

Changing the registry for another user isn't impossible, but it adds a lot of complexity.

The following script will give you an export for each user(as long as they are not logged in at the time)

I don't know how to use powercfg as a specific user...

Quote:

'vbscript Run for all profiles
Dim strOutputFile,strKeyName
Dim oShell : Set oShell = WScript.CreateObject("Wscript.Shell")
Dim oFS : Set oFS = WScript.CreateObject("Scripting.FileSystemObject")
Dim strCUProfile : strCUProfile = strCUProfile = oShell.Environment("Process")("UserProfile")
Dim oFolder

strKeyName = "HKEY_LOCAL_MACHINE\TempHive\Software\Active Voice\TeLANophy\Audio\Playback"

For Each oFolder In oFS.GetFolder("C:\Documents and Settings").SubFolders
If oFS.FileExists (oFolder &"\NTUser.DAT") _
And LCase(oFolder.Name) <> LCase(strCUProfile) _
And LCase(oFolder.Name) <> LCase("LocalService") _
And LCase(oFolder.Name) <> LCase ("NetworkService") _
And LCase(oFolder.Name) <> LCase("All Users") Then
strOutputFile = "c:\" & oFolder.Name & "_VMPlaybackDevices.txt"
oShell.Run "cmd /c reg load HKLM\TempHive " &Chr(34) &oFolder &"\NTUser.DAT" &Chr(34), ,1
oShell.Run "Regedit /E " & CHR(34) & strOutputFile & CHR(34) & " " & CHR(34) & strKeyName & CHR(34)
oShell.Run "cmd /c reg unload HKLM\TempHive", 0, True
End If
Next

Batch files in DS

Hello John,

I'm having the same problem. I'm trying to run the PowerCFG.exe in a batch file from DS. Did you solve the problem? I'm amazed that DS doesn't allow you to run as current user.

One way I have found around

Pikoshi's picture

One way I have found around the DS not letting me run jobs as the current logged on user is to use the DS to copy a batch file to the all users startup folder. The batch file then calls to the origional program that I wanted to run. Basically what this does is that the next time someone logs into the machine, it causes the batch file to be run, thus calling the script. The batch file you would need to copy would look like the following. We will call this run.bat.

echo off
C:
cd\

regedit /E "c:\VMPlaybackDevices.txt" "HKEY_CURRENT_USER\Software\Active Voice\TeLANophy\Audio\Playback"

POWERCFG /CREATE SCFGreenStar-laptop
POWERCFG /CHANGE SCFGreenStar-laptop /monitor-timeout-ac 15
POWERCFG /CHANGE SCFGreenStar-laptop /disk-timeout-ac 5
POWERCFG /CHANGE SCFGreenStar-laptop /standby-timeout-ac 30
POWERCFG /CHANGE SCFGreenStar-laptop /monitor-timeout-dc 3
POWERCFG /CHANGE SCFGreenStar-laptop /disk-timeout-dc 5
POWERCFG /CHANGE SCFGreenStar-laptop /standby-timeout-dc 15
POWERCFG /HIBERNATE ON
POWERCFG /GLOBALPOWERFLAG ON /OPTION BATTERYICON
POWERCFG /GLOBALPOWERFLAG ON /OPTION RESUMEPASSWORD
POWERCFG /GLOBALPOWERFLAG ON /OPTION VIDEODIM
POWERCFG /BATTERYALARM LOW /ACTIVATE ON /LEVEL 10 /TEXT on
POWERCFG /BATTERYALARM CRITICAL /ACTIVATE ON /LEVEL 3 /TEXT on /ACTION hibernate /FORCEACTION on
POWERCFG /SETACTIVE SCFGreenStar-laptop
del "C:\Documents and Settings\All Users\Start Menu\Programs\Startup\run.bat"
exit