Problem Executing Batch File

I wrote out a java class that I tried using cfobject to call. It didn't work. So I wrote a batch file to call the java class.  The batch file works, but NOt when I have coldfusion call it. Nothing happens, no error... nothing.  I thought it might be a permissions issue, but I tried changing permissions for coldfusion although I may have doneit wrong since I'm not too familiar with Vista.  Can anyone offer advice on what I can do.  Its a simple java class and I can't get it to run.  no errors in the log.  There isn't much for me to go on.  All I know is that the class and batch file work fine if Coldfusion doesn't call them.

Amosl wrote:
To limit the problems with the class itself and cfobject, I've created a batch file to run the class.  The batch file runs the class fine, so long as I execute the batch via command line.  But coldfusion doesn't execute the batch with cfexecute.  the same exact problem with absolutely no error messages.
Unfortunately, cfexecute is not the easiest tag to debug. In my experience sometimes it confuses more than clarifies.  But trying it is not a bad idea from a troubleshooting point of view.
However,  if I create a java class in the same folder that doesn't write to the system and only returns variables, it works fine.  This indicates the class path is set correctly and that cfobject does work.
Yes, I would agree.
It does sound like it might be a permissions issue. But I have little experience with Vista, so there may well be another cause.  Since it sounds like you are just testing a very simple java class, can you post the code for the class itself as well as the exact cfexecute code you are using? I could test it on another operating system. Just to see if there is some obvious problem.
Amosl wrote:
From the 100's of pages I've read online with people with similar problems, this seems to be a permissions issue.  however, I've set Coldfusion to run as me, the administrator and only person who uses this computer.  It is no longer running as local system.
However, this didn't fix anything.  My only guess is that perhaps I've no set it to run as me correctly.  But I have no way of testing this.  Windows logs show no error messages either.  Is there any way to have coldfusion show me what user its trying to execute the batch as.
I believe the user account can be obtained from the java system properties.  Try:
<cfset sys = createObject("java", "java.lang.System")>
<cfoutput>
   <b>user.name</b> = #sys.getProperty("user.name", "not found")#<hr>
   <b>coldfusion.classPath</b> = #sys.getProperty("coldfusion.classPath")#<br>
</cfoutput>

Similar Messages

  • Problem executing batch-file in external process

    Hi All,
    I'm having a problem doing something quite simple. I'm just trying to execute a very easy batchfile (just copy a file from one place to another).
    I've added the detail of the workflow process and the error message below. If anyone can help me, I would be very grateful.
    Thanks,
    Guy
    Execution Parameters
    Category Name Input Value Output Value
    System Command c:\windows\system32\cmd.exe
    System Parameter List ?/c?f:\\proc\\BI\\Check_source\\check.bat
    System Success Threshold 0
    System Use Return As Status false
    System Working Location Uoid (default)
    Activity Details
    Error Messages
    Severity Error Message Target Name Target Column View Diagnostic Report
    CreateProcess: c:\windows\system32\cmd.exe /c f:\proc\BI\Check_source\check.bat error=2

    In case anyone has this problem...I could not access this exe until I logged the JRun service on as a user other then the system. It now works just fine.

  • 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

  • Problem while executing batch file via jsp

    Scenario 1+
    I have a batch file(.bat) in which i have the following code
    mkdir d:\test\test1;
    mkdir d:\test\test2;
    mkdir d:\test\test3;
    mkdir d:\test\test4;
    mkdir d:\test\test5;
    mkdir d:\test\test6;
    mkdir d:\test\test7;
    mkdir d:\test\test8;
    mkdir d:\test\test9;
    mkdir d:\test\test10;when i double click on this or execute via cmd all the 10 directories are created successfully.
    Scenario 2+
    But when i try to execute this through a jsp using the following code,Only first 5 directories are created.Please help me in resolving the issue ASAP.Thanks in advance
    <%@page import="javax.swing.*"%>
    <%@page import="javax.swing.JFileChooser"%>
    <%@page import="java.awt.event.*"%>
    <%@page import="java.awt.*"%>
    <%@ page import="java.io.*"%>
    <%@ page import="java.util.*"%>
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
        <title>untitled2</title>
      </head>
      <body><%
            Runtime.getRuntime().exec("d:\\test.bat");
                    System.out.println("Inside Try Block");
                  %>
        hi</body>
    </html>I am using Jdeveloper.

    carrera wrote:
    Then can u suggest any other way how i can invoke a batch file from html/jsp.I think what some of the previous posters wanted to make clear is that jsps are not the place to go calling batch files. Jsp's are normally the view part and don't actually trigger these type of actions directly. Call a servlet to do non-view things...
    If all you want to do is execute an ant file, look for examples for running ant through java api. f.i. here

  • Error executing batch file within web application

    Hi all,
    I am trying to execute a batch file from within my web application (struts 1.2).
    The batch file is being kept inside the 'src' folder. The batch file contains only one command to open NOTEPAD.
    The code inside my Action class is:
    URL url = getClass().getResource("/test.bat");
    java.io.File file = new java.io.File(url.getPath()) ;
    String path = file.getCanonicalPath();
    r.exec(path);
    I have deployed this on tomcat and get an error like this:
    java.io.IOException: Cannot run program "C:\Program%20Files\Apache%20Software%20Foundation\Tomcat%206.0\webapps\CIGTAFAPP\WEB-INF\classes\test.bat": CreateProcess error=2, The system cannot find the file specified
    The problem is not with the batch file because when I try to execute the file directly from the classes folder, it opens up the notepad editor.
    I have a specific requirement where I need to create/read this batch file from within the project structure.
    Can someone please help me with this?
    Regards

    The entire content of the file is as below:
    set javaTestProjectPath=D:\projects\CIGTAF\LRTestCases
    C:
    cd %javaTestProjectPath%
    set path=C:\Program Files\Java\jdk1.6.0_21\bin
    set classpath=%javaTestProjectPath%\bin;%javaTestProjectPath%\lib\selenium-server-standalone-2.20.0.jar;%javaTestProjectPath%\lib\testng-6.4.jar;%javaTestProjectPath%\lib\junit-4.10.jar;%javaTestProjectPath%\lib\poi-3.6-20091214.jar;%javaTestProjectPath%\lib\mail.jar
    javac -verbose %javaTestProjectPath%\src\com\core\testscripts\Mailsetup.java -d %javaTestProjectPath%\bin
    javac -verbose %javaTestProjectPath%\src\com\core\testscripts\MailAuthenticator.java -d %javaTestProjectPath%\bin
    javac -verbose %javaTestProjectPath%\src\com\core\testscripts\ReadData.java -d %javaTestProjectPath%\bin
    javac -verbose %javaTestProjectPath%\src\com\core\testscripts\ReadWriteExcelResults.java -d %javaTestProjectPath%\bin
    javac -verbose %javaTestProjectPath%\src\com\core\testscripts\SeleniumFramework.java -d %javaTestProjectPath%\bin
    java org.testng.TestNG %javaTestProjectPath%\SelXD-Config.xml -d %javaTestProjectPath%\test-output
    none of these are getting executed.
    regards
    Edited by: 887789 on May 4, 2012 1:46 AM

  • 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

  • Execute batch file

    Hello,
    I have a simple and short batch file I am trying to execute from SQL server. The SQL database I am connected to is my local instance. The script I am using is as below:
    EXECUTE [master].[dbo].[xp_cmdshell] 'C:\Users\Jdoe\Desktop\Test.bat'
    The batch file is located at the path listed above and contains the below:
    SchTasks /query /fo csv > I:\Schedtask.txt /v /s reports.xyz.org
    The above command line code connects to a remote machine and gets the list of all scheduled tasks. Please note that executing the batch file by double-clicking on the icon works without issues. When I try however to run the SQL listed above, I get the below:
    output
    NULL
    C:\Windows\system32>SchTasks /query /fo csv /v /s reports.xyz.org 1>I:\Schedtask.txt
    The system cannot find the path specified.
    NULL
    What am I doing wrong. I am expecting the SQL to execute de batch file which should create a output file at the specified location but it doesn't.
    Thanks for helping

    Try to use UNC path (\\server\share\file_path). Also make sure that the doamain account used as task owner has the proper rights on the source and destination
    Javier Villegas |
    @javier_vill | http://sql-javier-villegas.blogspot.com/
    Please click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you

  • Can Java execute batch file outside of current JVM in separate process tree

    Hi,
    Does anyone know how to run programs from Java as separate processes that will not die when the spawning java program exits (JVM exits).
    The problem I have with using Runtime.exec is it spawns only child processes under the current running JVM, thus when the origonal program that called Runtime.exec ends so does all child processes.
    Basically I want to start a DOS batch file from my Java application, my Java application will then immediately exit (calling System.exit(0) ). The batch program will continue to run, its does some file clean up, create's some new files and deletes the old jar (containing the main app), it then rebuilds the main app jar and and executes the main class and then exits itself.
    I've also tried the apache.tomcat.jni.Proc :-
    long pool = Pool.create( new Long(0).longValue() );
    long pa = Procattr.create( pool );
    Procattr.dirSet( pa, "c:\\temp\\updater\\");
    Procattr.cmdtypeSet( pa, Proc.APR_SHELLCM );
    Procattr.detachSet( pa, 1 );
    long proc = Proc.alloc( pool );
    Proc.create( proc, "test.bat", new String[]{"test.bat"}, null, pa, pool );
    System.exit(0);
    The detach option doesn't work, if I take it off then the bat file runs and stops the JVM exiting, if I leave it in the batch file never gets called.
    Is this possible in Java. Can java start master process on Windows XP JDK1.5+?
    Cheers
    Chris.

    Well I found the answer elsewhere (java.net) thought I'd post it here for future visitors who might be experience the same problem.
    Basically Runtime can do this however it must be done the following way :-
    The java:-
    public class Main {
        public static void main(String[] args) throws Exception {
            Process p=Runtime.getRuntime().exec("cmd /c c:\\test.bat");
            System.out.println("done");
            System.out.println("quitting");
            System.exit(0);
    }The batch:-
    @echo off
    PING 1.1.1.1 -n 1 -w 5000 >nul
    java -cp "c:\ " MainThe important line that makes the whole thing work is :-
    @echo offIf this line is missing then the whole things locks up (must be the io streams getting used)
    Also this code can not be run from an IDE (well at least not from Intellj) as it also locks up.
    It must be run from a command prompt or jar.
    Also note that any commands in the batch file must have there output redirected to "nul" otherwise Windows kills the cmd as soon as it trys to output to a dead stream (dead because the Java has exited). for example :-
    @echo off
    PING 1.1.1.1 -n 1 -w 10000 >nul
    cd %1
    del /F /Q *.* >nul
    move /Y new\*.* >nul
    RD /Q /S new >nul
    PING 1.1.1.1 -n 1 -w 1000 >nul
    java -cp "c:\ " Main
    exit

  • Problem executing .bat file from within Java class

    I'm stumped: I have no problem executing a .bat file that sets classpaths and executes a Java jar, but when I try to execute other executables first and then the .jar, my application hangs and since the DOS box doesn't come up over my GUI, I can't see what's going on.
    This works:
    public void execute() throws Exception {
    String s = "c:\\cs47auxs\\omnijar\\omni.bat";
    Process p = Runtime.getRuntime().exec("\"" + s + "\"");
    p.waitFor();
    JOptionPane.showMessageDialog(frame,
    "The Database Has Been Successfully Reloaded.",
    "Information Message",
    JOptionPane.INFORMATION_MESSAGE);
    Here's the .bat 'omni.bat'
    set JAVA_HOME=c:\j2sdk1.4.2_04\bin
    %JAVA_HOME%\java -jar C:\CS47AUXS\OMNILOADJAR\OmniLoad.jar
    This doesn't work:
    public void execute() throws Exception {
    String s = "c:\\cs47auxs\\omnijar\\jobomni.bat";
    Process p = Runtime.getRuntime().exec("\"" + s + "\"");
    p.waitFor();
    JOptionPane.showMessageDialog(frame,
    "The Database Has Been Successfully Reloaded.",
    "Information Message",
    JOptionPane.INFORMATION_MESSAGE);
    Here's the .bat file 'jobomni.bat'
    SET NETX_HOME=C:\CS47AUXS
    SET COBOL_HOME=C:\CS47AUXS\OFFLINE
    CD %NETX_HOME%
    CALL SET-NETX.CMD
    CD %COBOL_HOME%
    SSBPPC10 JOBOMNI X
    SET JH=C:\J2SDK1.4.2_04\BIN
    SET OMNI_HOME=C:\CS47AUXS\OMNILOADJAR
    CD %OMNI_HOME%
    %JH%\java -jar omniload.jar
    Can anyone shed some light here? Even when I execute the application from the command line the new DOS box doesn't become visible nor can I see any errors. If I could just get that visibility, I could probably figure out what is going wrong.

    Same problem with me as well.... Badly looking for a solution...
    I predict the following:
    - If your batch file has pretty less number of dos/shell commands then it gets executed fine with exec() and proc.waitFor();
    - If you increase the number of dos/shell commands in the bat file then try executing it then it definately hangs at proc.waitFor();
    Even "cmd.exe /C C:\\test.bat" hangs... if the commands are more...
    Is this some sort of bug? or am i doing anything wrong? I tried searching for solution on the net and search forums... but couldnt find a solution for the same.. not sure where i missed, what i missed...
    Incase some one finds a solution.. do post it here...
    Message was edited by:
    amadas

  • Executing batch file as administrator changes working directory

    hey guys,
    I already posted this question on the msdn-forums and they sent me here. I hope, you can help me.
    My situation: I have a java program which I compile with exe4j. exe4j adds some nice features so I can install the program as a service with the command "myexe.exe /install"
    I put that command in a batch file (more user friendly).
    The problem: Only administrators can install services (in Win 7). But if I run the batch-file as administrator, the working directory changes to the system32-directory and I get an "command not found"-error.
    The question: How can I solve this? The only solution I know at the moment is setting a environment variable at installation time that points to the install-location. Is there another way?
    Thx for your help in advance

    With runas you in fact logon to another seesion. So cmd is started with his own starting directory (being where it is located, system32).
    I would recommend never to rely on the working dir for a batch file or script, but to always include the full path to the needed command/executables. If needed you can use environment variables to get the pathes of user-customised folders (for example the %usersprofile% variable).
    Using .lnk files (normal shortcuts) you can specify the working dir to start in if you would really need that functionality.
    MCSA/MCTS/MCP

  • Executing batch file using SM49 Tcode

    Hi,
    Theirs a batch file which is used to encrypt a text file ie from '.txt' to '.enc'.
    Seperate Encryption software and Java Pakage is used.
    When in SM49 the operating system command is executed,its throwing error
    File Not Found Exception.
    ie call failed
    Java.io.filenotfoundexception :  ..\logs\star_pkcs7-client-events.log(The system cannot find the path specified)
    OS is WinNt,File is encrypting at OS level seperately.
    All authorisation issue has been taken care of.
    If any questions or need information then plz ask
    Help me on this...its urgent

    hi,
    well try the following
           String cmdLine[] = {"cmd.exe","/c","copy.bat"};       Runtime.getRuntime().exec(cmdLine);it works fine in Win NT, the process terminates normally.
    cheerz
    ynkrish

  • 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
    ¯\_(ツ)_/¯

Maybe you are looking for