DSC powershell xwindowsprocess to execute batch file under different user account

DSC powershell run under "NT AUTHORITY\SYSTEM".
I am trying to execute a batch file under different user account using xwindowsprocess in DSC resource kit.
I created a custom dsc resource with 3 parameters namely Exepath, Arguments, Credential.
I received those parameter values in settargetresource method.
CallPInvoke
[Source.NativeMethods]::CreateProcessAsUser(("$ExePath "+$Arguments), $Credential.GetNetworkCredential().Domain, $Credential.GetNetworkCredential().UserName, $Credential.GetNetworkCredential().Password)
I tested it by invoking a batch file and writing username under which it executes to a text file.
After executing, the output text file still contains the "Systemname$".

Configuration Sample_xService_ServiceWithCredential
param
[string[]]
$nodeName = 'localhost',
[System.String]
$Name,
[System.String]
[ValidateSet("Automatic", "Manual", "Disabled")]
$StartupType="Automatic",
[System.String]
[ValidateSet("LocalSystem", "LocalService", "NetworkService")]
$BuiltInAccount="LocalSystem",
[System.Management.Automation.PSCredential]
$Credential,
[System.String]
[ValidateSet("Running", "Stopped")]
$State="Running",
[System.String]
[ValidateSet("Present", "Absent")]
$Ensure="Present",
[System.String]
$Path,
[System.String]
$DisplayName,
[System.String]
$Description,
[System.String[]]
$Dependencies
Import-DscResource -Name MSFT_xServiceResource -ModuleName xPSDesiredStateConfiguration
Node $nodeName
xService service
Name = $Name
DisplayName = $DisplayName
Ensure = $Ensure
Path = $Path
StartupType = $StartupType
Credential = $credential
$Config = @{
Allnodes = @(
Nodename = "localhost"
PSDSCAllowPlainTextPassword = $true
#Sample Scenarios
$credential = Get-Credential
Sample_xService_ServiceWithCredential -ConfigurationData $Config -Name "Sample Service" -DisplayName "Sample Display Name" -Ensure "Present" -Path "C:\DSC\TestService.exe" -StartupType Automatic -Credential $credential
¯\_(ツ)_/¯

Similar Messages

  • Read/Write App Files Under Limited User Account

    Hi All,
    My desktop app is intended for Windows only. I'm writing files to the hard disk to store app specific configuration.
    The applications main data source is a ZIp file that consists several XML files. The user can store this ZIP anywehre they like and the application will extract the necessary files to a temp dir so that it can read in data.
    When logged into a PC as either an Administrator or Power User, I am able to read write my config files and extract XML files from the ZIP with no problem.
    When logged in as a user with "limited" access, I can only read and write the config files. But when I go to extract any XML files from the ZIP, it seem to get denied due to insufficient permissions.
    The working directory for storeing all these files is: C:\Documents and Settings\<USER NAME>\Application Data\<MY APP>\
    Don't users with limited access have full read/write permissions to their own home directory?
    If not, what can be done to give them full read write access? Is there perhaps some other location I should be using?
    Also, would code signing from some place like Verisign do any good?
    I'm targeting Windows 2000/XP.
    Thanks in advance.
    Regards,
    Jim

    You can also access the user folder through the registry:
         public static final String APP_DATA_FOLDER_CMD = REG_QUERY_UTIL
              + "\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\"
              + "Explorer\\Shell Folders\" /v AppData";
          * Gets the current user Application Data folder path defined in the
          * registry.
          * @return The current user Application Data folder path.
         public static String getCurrentUserAppDataFolderPath()
              return queryREG_SZ(APP_DATA_FOLDER_CMD);
          * Performs the query in the registry for the specified value type.
          * @param queryString The query to be performed.
          * @param valueType The value type.
          * @return The value data for the specified value name in the registry.
         public static String queryREG_SZ(String queryString, String valueType)
              try
                   Process process = Runtime.getRuntime().exec(queryString);
                   StreamReader reader = new StreamReader(process.getInputStream());
                   reader.start();
                   process.waitFor();
                   reader.join();
                   String result = reader.getResult();
                   int p = result.indexOf("REG_SZ");
                   if (p == -1)
                        return null;
                   return result.substring(p + valueType.length()).trim();
              catch (Exception e)
                   return null;
         }This will get you the user directory from the registry. However, my issue is
    that the value returned was:
    C:\Documents and Settings\<USER NAME>\Application Data
    Which is great, but that folder didn't exists on my computer. I cannot find
    any documentation to say why it would be there. Except I had no Application
    Data folders under any user. I have XP.
    So when running the program on one computer, I had no valid folder to write
    to and it wouldn't let me create it. Said the <USER NAME> folder could not
    be written to. canWrite() returned false and the directory could not be
    created.
    On another computer, I had the Application Data folder, the canWrite()
    returned false, yet I was able to create a folder and file inside.
    I checked the default <ALL USERS> directory and the Application Data folder
    did not exist there.
    I don't understand how I am supposed to work around it...
    If the folder doesn't exist, I need to be able to create it, whether it's in the
    <ALL USER> or <USER NAME> folder.
    I guess I am counting on the canWrite() to be accurate. Yet it appears that
    I cannot rely on the canWrite() since a false was returned. I wrote!!
    So confused ... need to be able to write to this folder on any computer...
    Help!!

  • Sharing files among different user accounts -- file/folder permissions?

    I have two main user accounts that I switch between during the day (essentially a PERSONAL account and a WORK account). This allows me to keep separate Mail, iCal, etc -- as well as desktop applications and file organization. However, I am having some major issues with sharing data between the user accounts.
    WHAT I WANT: A local drop box for shared communal files between these two primary users. Seems simple enough, right?
    WHAT I DID: I created a subfolder in /Users/Shared/ called "COMMUNAL DROP BOX" and set the permissions to R/W for both my user accounts, and no access for the other accounts. However, when I copy files into this folder from my PERSONAL account -- it retains the file level permissions. For example, I grabbed some photos from my iPhone that I shot of a display for work -- I grabbed them off the phone and then dragged them into the drop box. They are in the shared folder, but the file perms are set to PERSONAL_ACCOUNT "Read & Write" and Everyone "No Access." There's no way I can continue to individually change every single file's permission -- how do I set it up to automatically match the folder, so that files like this are then readable by my work account?
    -Jason M.

    On my machine I've created a directory(folder) in the /Users directory called localshare. Since the directory can have just one owner, I've made root own the folder.
    sudo mkdir /Users/localshare
    Every user on my machine belongs to the group-Staff. I need to change the group class on the localshare directory that I've created.
    sudo chown :staff /Users/localshare
    As a reference, I changed the traditional permissions to reflect my desired results and lock down the permissions some.
    sudo chmod 770 /Users/localshare
    I have added an ACL on the localshare directory that allows the group staff to do anything within the directory- make file and directories, modify files that they do not owner, etc.
    sudo chmod +ai "staff allow list,addfile,search,delete,add_subdirectory,delete_child,readattr,writeattr,readextattr,writeextattr,readsecurity,file_inherit,directoryinherit" /Users/localshare
    This works well for me with one issue. Files or folders must be copied to the localshare directory. They cannot be moved.
    Message was edited by: Mark Jalbert

  • PowerPoint file won't open under one user account, but does under another account

    Hello,
    I have a 10.9.5 macbook pro here that will not open a Powerpoint file under one user account. It is up-to-date with Software updates and Office 2008 is up-to-date as well. When I try to open the PowerPoint file, I get the message, "PowerPoint closed unexpectedly" and I can choose to Reopen (which opens a blank presentation) or OK (which closes PowrPoint). I have tried double-clicking the file from the Desktop where is resides, File --> Open from within PowerPoint and also saved it to a flash drive and tried opening from there. It does open under the admin account on the same machine and it will also open on other machines. Other PowerPoint files are opening fine...it's just a problem with the one file. The user has Read & Write privilege to the file. I tried Repairing Disk Permissions, I have tried deleting microsoft plist files, and lastly, have re-installed Office 2008. At this point, I can only think to try deleting the user account and re-adding it, but wanted to see if anyone had any ideas before I go that route.
    Thanks in advance for any suggestions!

    Back up all data before proceeding.
    This procedure will unlock all your user files (not system files) and reset their ownership, permissions, and access controls to the default. If you've intentionally set special values for those attributes on any of your files, they will be reverted. In that case, either stop here, or be prepared to recreate the settings if necessary. Do so only after verifying that those settings didn't cause the problem. If none of this is meaningful to you, you don't need to worry about it, but you do need to follow the instructions below.
    Start up in Recovery mode. When the OS X Utilities screen appears, select
              Utilities ▹ Terminal
    from the menu bar. A Terminal window will open. In that window, type this:
    res
    Press the tab key. The partial command you typed will automatically be completed to this:
    resetpassword
    Press return. A Reset Password window will open. You’re not going to reset a password.
    Select your startup volume ("Macintosh HD," unless you gave it a different name) if not already selected.
    Select your username from the menu labeled Select the user account if not already selected.
    Under Reset Home Directory Permissions and ACLs, click the Reset button.
    Select
               ▹ Restart
    from the menu bar.

  • Executing batch files from websevice using ODI OS Command

    Hi,
    Is it possible to execute the batch files using odi os command from webservices.
    We have developed a webservice, which passess some parameters to one batch file and after that we executing the same batch file in package using odi os command. In opeartor is showing as running, it never ends.
    But if we run the same package from designer, it is executing successfully. Also the same web service is working fine for executing non batch scenarios.
    what could be the problem??
    We got one possible reason for failure...
    For executing the batch from web services, we need read and executable permissions on the drive where batch sits.
    We are logging into ODI using SUPERVISOR. How to give the permissions to SUPERVISOR as we are having windows authentication.
    Edited by: Naveen Suram on Dec 17, 2009 8:07 PM
    As a work around, can we use ODIOSCommand instead of OS Command. But it is asking for starting event? Whether both the commands does the same functionality??
    Edited by: Naveen Suram on Dec 17, 2009 9:08 PM

    From the FAQ:
    2. How do you launch an external program on a Microsoft Windows platform from a program developed on the Java [tm] programming language?
    The following will launch notepad in Microsoft Windows NT:
    Runtime.getRuntime().exec("cmd /c notepad.exe");
    To launch a program in Microsoft Windows 95/98 use:
    Runtime.getRuntime().exec("c:\\windows\\notepad.exe");
    The Runtime class allows interaction between a program and its environment. The first string command instructs the command line interpretor, cmd to open up the calculator application.
    The exec() methods do not use a shell; any arguments must have the full pathname to the shell as well as the command itself.
    For example, to run a shell on the UNIX� platform, type:
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("/usr/bin/sh -c date");
    To run a batch file under Microsoft Windows 95/98:
    Process p = rt.exec("command.com /c c:\\mydir\\myfile.bat");
    To run a batch file under Microsoft Windows NT:
    Process p = rt.exec("cmd /c c:\\mydir\\myfile.bat");
    where 'cmd' and 'command.com' are the command-line interpreters for Microsoft Windows machines.
    The Runtime.exec() methods might not work effectively for some processes on certain platforms. Special care should be taken with native windowing, daemon, WIN16/DOS process or some shell scripts.
    regards,
    jarshe

  • Executing batch file from Java stored procedure hang

    Dears,
    I'm using the following code to execute batch file from Java Stored procedure, which is working fine from Java IDE JDeveloper 10.1.3.4.
    public static String runFile(String drive)
    String result = "";
    String content = "echo off\n" + "vol " + drive + ": | find /i \"Serial Number is\"";
    try {
    File directory = new File(drive + ":");
    File file = File.createTempFile("bb1", ".bat", directory);
    file.deleteOnExit();
    FileWriter fw = new java.io.FileWriter(file);
    fw.write(content);
    fw.close();
    // The next line is the command causing the problem
    Process p = Runtime.getRuntime().exec("cmd.exe /c " + file.getPath());
    BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line;
    while ((line = input.readLine()) != null)
    result += line;
    input.close();
    file.delete();
    result = result.substring( result.lastIndexOf( ' ' )).trim();
    } catch (Exception e) {
    e.printStackTrace();
    result = e.getClass().getName() + " : " + e.getMessage();
    return result;
    The above code is used in getting the volume of a drive on windows, something like "80EC-C230"
    I gave the SYSTEM schema the required privilege to execute the code.
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'java.io.FilePermission', '&lt;&lt;ALL FILES&gt;&gt;', 'read ,write, execute, delete');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
    EXEC DBMS_JAVA.grant_permission('SYSTEM', 'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
    GRANT JAVAUSERPRIV TO SYSTEM;
    I have used the following to load the class in Oracle 9ir2 DB:
    loadjava -u [system/******@orcl|mailto:system/******@orcl] -v -resolve C:\Server\src\net\dev\Util.java
    CREATE FUNCTION A1(drive IN VARCHAR2) RETURN VARCHAR2 AS LANGUAGE JAVA NAME 'net.dev.Util.a1(java.lang.String) return java.lang.String';
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    The problem that it hangs when I execute the call to the function (I have indicated the line causing the problem in a comment in the code).
    I have seen similar problems on other forums, but no solution posted
    [http://oracle.ittoolbox.com/groups/technical-functional/oracle-jdeveloper-l/run-an-exe-file-using-oracle-database-trigger-1567662]
    I have posted this in JDeveloper forum ([t-853821]) but suggested to post for forum in DB.
    Can anyne help?

    Dear Peter,
    You are totally right, I got this as mistake copy paste. I'm just having a Java utility for running external files outside Oracle DB, this is the method runFile()
    I'm passing it the content of script and names of file to be created on the fly and executed then deleted, sorry for the mistake in creating caller function.
    The main point, how I claim that the line in code where creating external process is the problem. I have tried the code with commenting this line and it was working ok, I made this to make sure of the permission required that I need to give to the schema passing security permission problems.
    The function script is running perfect if I'm executing vbs script outside Oracle using something like "cscript //NoLogo aaa1.vbs", but when I use the command line the call just never returns to me "cmd.exe /c bb1.bat".
    where content of bb1.bat as follows:
    echo off
    vol C: | find /i "Serial Number is"
    The above batch file just get the serial number of hard drive assigned when windows formatted HD.
    Same code runs outside Oracle just fine, but inside Oracle doesn't return if I exectued the following:
    variable serial1 varchar2(1000);
    call A1( 'C' ) into :serial1;
    Never returns
    Thanks for tracing teh issue to that details ;) hope you coul help.

  • Execute batch file having gmake command

    Hi,  I am executing batch file having gmake command in it, when i run batch file directly it works correctly,
    but when i try to execute it from LabVIEW using system Exec.vi  
    i got following error,  
    process_easy: DuplicateHandle(In) failed (e=6)
    process_easy() failed to launch process (e=6)  
    Thanks in advance

    What OS?
    How are you calling it in LV?
    What is in the batch file?
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • How to execute batch file from JSP

    hi frens !
    i wanna know how to execute batch file from my JSP.i am using exec() method to get call the batch file. but its not working ....plz help
    here mine code:-
    File F = new File("C:/var.bat");
         try{
          if (F.exists())
            Runtime rt = Runtime.getRuntime();
            String url=F.getAbsolutePath();
             Process proc = rt.exec(url);
            proc.waitFor();
            proc.destroy();
            catch(Exception IOEx){
           System.out.println(IOEx);
      }Thanks and Regards
    Allwyn

    You might improve your chances of getting help if you do two things:
    1) Explain what "not working" means.
    2) ChangeSystem.out.println(IOEx); to IOEx.printStackTrace(); (in the eventhat is in fact related to "not working").

  • Executing Batch files from Runtime.getRuntime().exec

    Can we execute batch files from Runtime.getRuntime().exec() method.
    Regards,
    Nalini

    hi,
    import java.io.IOException;
    class BatchFileTest{
         public static void main(String args[]){
              try{
              Runtime r = Runtime.getRuntime();
              Process p = r.exec("startcmd.bat");
              catch(IOException en){
                   en.printStackTrace();
    -Regards
    Manikantan

  • Batch file execution using user defined activity

    Can anyone please explain me what is the structure of the user defined activity in order to execute batch file. I've read like 10 post about this problem in this forum but nothing seems to work. So to finally clear it out...
    I have simple batch file d:\test_dir\test.bat that has only one line in it "echo this is test>>test.txt"
    what should i put in the user defined activity setting?
    COMMAND = ?
    PARAMETER_LIST = ?
    RESULT_CODE = ?
    SCRIPT = ?
    SUCCESS_THRESHOLD = ?
    i have the setting in the runtime.properties file to:
    property.RuntimePlatform.0.NativeExecution.FTP.security_constraint = DISABLED
    property.RuntimePlatform.0.NativeExecution.Shell.security_constraint = NATIVE_JAVA
    property.RuntimePlatform.0.NativeExecution.SQLPlus.security_constraint = NATIVE_JAVA
    property.RuntimePlatform.0.NativeExecution.OMBPlus.security_constraint = DISABLED

    Did you read this blog?
    https://blogs.oracle.com/warehousebuilder/entry/how_to_use_user_defined_activity_in_owb_process_flow
    What error do you get? Did you stop/start the runtime service after changing the parameter file?
    Cheers
    David

  • I recently purchased a MacBook Pro, I did not transfer files from my old pc with migration assistant when I set up the MacBook. A few days later I did the transfer, now my Itunes library and everything else from my old pc is under a different user account

    I've already setup the original user account and do not want to do it again, how do I merge the two user accounts into one so all of my stuff is under one user account?

    They are the same Itunes account (mine), but since I transferred the 'user account' with my Itunes library and other files from old pc to my new MacBook, I now have two 'user accounts' on my MacBook. The original I setup when I got the MacBook and the one I transferred from my pc. I've already went thru most of my photos in Iphoto and named all the faces along with general setup of how I want all my settings on my MacBook under the first user account, I don't want to start over and do it all again with the transferred user account, I just want to move my Itunes library I transferred over to my original user account on my MacBook. Does this make any sense? lol

  • I downloaded itunes 10.5.  During  install I get a message that states the file cannot be located because it is on a network resource that is unavailable.  I tried to locate the file,but cannot find the apps file under my user name or any other place

    I downloaded itunes 10.5 on my laptop.  upgrade from 10.4.1.  Install was terminated because "the feature you are using is on a network resurce that is unavailable.
    I tried to locate the file under my user name sub file apps, but could not

    you need to specify the database when you exec. the commands.
    ALTER DATABASE database_name SET ENCRYPTION OFF --> user database.
    DROP DATABASE ENCRYPTION KEY --> user database.
    DROP CERTIFICATE certificate_name --> master database
    DROP MASTER KEY --> master database.
    Best Regards,
    Ahmad Elayyan.
    Regards, Ahmad Elayyan Database Team Leader

  • Can I delete the files under C:\Users\MyAccount\CS6 Master Collection\Adobe CS6

    After installation I've been left with a ton of files under C:\Users\Nathan\CS6 Master Collection\Adobe CS6 - 8.3GB.
    Are these files actually needed? They seem to mostly be setup files. Can I just delete them after installation?

    Hi Nathan,
    The default location for software installation is the program files folder and the default location for the extracted files is usually desktop from where the installation is initiated. You might have chosen the aforementioned folder for extraction.
    If you have already installed the software you can go ahead and delete this folder.

  • Sharing files on same iMac under different users

    i have two different user accounts set up on my iMac and i want to be able to have the files from both accounts open to each other or either just merge them together.does anybody know how to help one way or the other?

    Transferring files from one User Account to another

  • Can you move files between two different user accounts in Time Capsule?

    I copied a bunch of stuff from my old NAS (which used FAT) to Time Capsule under one user account... I then reformatted the NAS to HFS+ so I could just use it as a USB drive connected to the TC. Now I realized that I want to have one of those folders in another user directory. I cannot open two different sessions of the TC on the computer...at least I have not figured out how to do this. Is there a way to accomplish this without copying the folder to my computer, then copying it back to the other user directory? It is several gigs.

    you can crop files from one account to another using the Public Dropbox which every user account has.  Log into the user that has the files you want to move, then drag the folder you want to the new users' dropbox:
    I suggest a small scale test on a few files first before moving gigabytes of files.

Maybe you are looking for

  • Loops

    Some of my loops only last for about 20 seconds then fade away. I have extended the length of the loop and it appears to be reading the music but not playing any sound. ANy thoughts?

  • Final Cut Pro X and JVC camera

    Can anyone who saw the April preview of Final Cut Pro X tell me if it will contain the necessary codec for my JVC GY - HM100U camera? Many thanks.

  • Error in J2ee .war file deployment using ASC

    Hi, When I deploy a .war file using Application Server Control web interface, after 30 min or so, it gave me an error: "Processing has already completed". But when I checked, no application was deployed. Sometimes the same war file deployment finishe

  • Upgrading JVM in 10g and 9 - again

    Hi I need to have Java 1.5 in Oracle Database 10 and 9. I know that there was a disscussion on this in Re: Oracle 9.2 update jvm's jdk? But it was 2007. Has something change in this matter ?? Kuassi wrote "We are looking into this for future releases

  • Flash Player 10 compatibility

    We just installed CS4 Production Premium, which also installs Flash Player 10. The videos placed in Captivate 3 will no longer play in preview or when published. They do play in another PC with Flash Player 9. We had the same issue in Articulate and