Keep ShellExecuteExW's command prompt opened - c++

I'm trying to use ShellExecuteExW to run a bat file.
I want the command prompt to be kept opened after the bat file has been executed.
Here's what I tried,
SHELLEXECUTEINFOW TempInfo = { 0 };
TempInfo.cbSize = sizeof(SHELLEXECUTEINFOA);
TempInfo.fMask = 0;
TempInfo.hwnd = NULL;
TempInfo.lpVerb = L"runas";
TempInfo.lpFile = L"cmd.exe";
TempInfo.lpParameters = L"\\k runMe.bat StartTool";
TempInfo.lpDirectory = NULL;
TempInfo.nShow = SW_NORMAL;
::ShellExecuteExW(&TempInfo);
But what I see is my cmd.exe stays opened but it didn't actually ran my runMe.bat file.

#dewaffled answered it... /k instead of \\k

Related

Sending argument to an .exe via SHELLEXECUTEINFO

I have an .exe which takes 2 arguments. I need to run the .exe file between my program in runtime. I have used ShellExecuteEx to run the .exe file but it is not taking the arguments. Please help where did i went wrong. I am posting my code below.
void StartProgram() {
SHELLEXECUTEINFO lpExecInfo;
lpExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
lpExecInfo.lpFile = L"F:\\EXEFolder\\RunMe.exe"; // Path to the .exe
lpExecInfo.fMask = SEE_MASK_DOENVSUBST | SEE_MASK_NOCLOSEPROCESS;
lpExecInfo.hwnd = NULL;
lpExecInfo.lpVerb = L"open"; // to open program
lpExecInfo.lpParameters = L"D:/input.csv" "F:/output.csv;"; //Arguments to be passed to .exe
lpExecInfo.lpDirectory = NULL;
lpExecInfo.nShow = SW_SHOW;
lpExecInfo.hInstApp = (HINSTANCE)SE_ERR_DDEFAIL;
ShellExecuteEx(&lpExecInfo);
//wait until a file is finished printing
if (lpExecInfo.hProcess != NULL)
{
::WaitForSingleObject(lpExecInfo.hProcess, INFINITE);
::CloseHandle(lpExecInfo.hProcess);
}
}
The lpParameters member is a pointer to a space-delimited string of arguments, just like you would pass them in a command-line environment.
If you want to pass two arguments to the program, you do it like
lpExecInfo.lpParameters = L"argument1 argument2";
For your case it should be like
lpExecInfo.lpParameters = L"D:/input.csv F:/output.csv";
To explain what you do wrong, the C++ compiler have a phase where it concatenate adjacent string literals into a single string. That means L"D:/input.csv" "F:/output.csv;" will be concatenated into L"D:/input.csvF:/output.csv;" which is a single argument.

How do you remove / delete a remote FTP file using cfscript?

My script is working so far to open a remote FTP connection, change directory, and download a file. My last two steps would be to delete the remove file once it's fully downloaded and then close the connection. ACF documentation (and cfdocs) seems to have very little information on this. Here's what I have so far:
ftpConnection = ftpService.open(
action = 'open',
connection = variables.ftpConnectionName,
server = variables.ftpServerName,
username = '***************',
password = '***************',
secure='true');
if( ftpConnection.getPrefix().succeeded ){
fileList = ftpService.listdir(directory = variables.ftpPath, connection= variables.ftpConnectionName, name='pendingFiles', stopOnError='true').getResult();
if( fileList.recordCount ){
changeFtpConnectionDir = ftpService.changeDir(
connection = variables.ftpConnectionName,
directory = variables.ftpPath);
getFtpConnection = ftpService.getFile(
connection = variables.ftpConnectionName,
remoteFile = fileList.name,
localFile = local.localPath & fileList.name,
failIfExists = false,
timeout = 3000
);
deleteRemoteFile = ftpService.remove(
connection = variables.ftpConnectionName,
remoteFile = fileList.name
};
closeFtp = ftpService.close(
connection = variables.ftpConnectionName
);
};
};
Error is thrown on the remoteFile = fileList.name. Since I already changed directory I don't think I need to put the full path here.
I put the entire script up since there doesn't seem to be many resources out there about using the newer ftpServer() functions.
D'oh - my issue was a typo:
deleteRemoteFile = ftpService.remove(
connection = variables.ftpConnectionName,
remoteFile = fileList.name
);// had } instead of )
I'll still leave this up as a resource for ftpService()

How to provide a XPS file path as a local port?

Below here is a code snippet what I m trying out:
PRINTER_INFO_2 pi;
BOOL Result = FALSE;
HANDLE pHd;
memset(&pi, 0, sizeof(PRINTER_INFO_2));
pi.pPrinterName = L"RxXPSDrv";
pi.pDriverName = L"XPSDrv Sample Driver";
// Select Share Name
pi.pShareName = L"MyPrinter";
// Select Server Name
pi.pServerName = NULL;
// Select Port Name
pi.pPortName = L"COM3:";
//pi.pPortName = L"C:\\Users\\admin\\Desktop\\a1.xps";
pi.pSecurityDescriptor = NULL;
// Select Print Processor
pi.pPrintProcessor = L"winprint";
// Select Attributes
pi.Attributes = PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST | PRINTER_ATTRIBUTE_LOCAL;
// Set Priority
pi.Priority = 1;
// Call the function AddPrinter
pHd = AddPrinter(NULL, 2, (LPBYTE)&pi);
Here #pi.pPortName I need to provide C:\Users\admin\Desktop\a1.xps but its not working and the printer isn't getting added. With COM3 it works fine.
Can anyone tell me how can I do this? How can I provide full path of a XPS to pi.pPortName?
You have to add a "local port" "C:\Users\admin\Desktop\a1.xps" first. I just tried and it worked. Some code for Add port: Adding-a-Local-Port-through-XcvData-and-C

Is there possible get the prompts list from BO file via using NET BO SDK?

Is there possible get the prompts list from BO file via using BO NET SDK?
for example, I launch a application, then load a rep file, after that, the application tell me, in this rep file, there are 3 prompts
First one is:???? type is:???
2nd one is:??? type is:???
3rd one is:??? type is ???
busobj.Application boApp = new busobj.Application();
boApp.Logon(GlobalClass.user.strUsrId, GlobalClass.user.strPWD, "#bopfast", "LDAP", false, false);
boApp.Interactive = false;
boApp.Visible = false;
busobj.Document testDoc = new busobj.Document();
testDoc = (busobj.Document)boApp.Documents.Open("C:\\test.rep", true, false, null, null);
I know it's possible to do this in Java :
/* Connect to CMS */
ISessionMgr sessionMgr = CrystalEnterprise.getSessionMgr();
enterpriseSession = sessionMgr.logon(user, pass, host, auth);
/* Initialize Webi report engine */
reportEngines = (ReportEngines) enterpriseSession.getService("ReportEngines");
ReportEngine reportEngine = (ReportEngine) reportEngines.getService(ReportEngines.ReportEngineType.WI_REPORT_ENGINE);
/* Open report */
DocumentInstance doc = reportEngine.openDocument(rapport_id);
doc.refresh();
/* Get Prompts */
Prompts prompts = doc.getPrompts();
System.out.println("Total Prompts : " + prompts.getCount())
Prompts prompts = doc.getPrompts();
for (int s = 0; s < prompts.getCount(); s++) {
Prompt prompt = prompts.getItem(s);
System.out.println("Prompt name : " + prompt.getID());
}
You can find some samples here for .NET SDK : http://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports+for+.NET+SDK+Samples
And here you have Sample Applications for Business Intelligence Software Developer Kits :
http://scn.sap.com/docs/DOC-51445
Hope it helps.

How To Open, Read Output and Give Input To a .jar file with C++?

I would like to make a GUI to host a Minecraft Server in Windows. Minecraft servers use a .jar file and a .bat file to run the .jar file and read output and give input to/from it.
How to make a C++ program that will open the .jar file, read the output and give input to it?
I tried with execlp, but when I #include <unistd.h> I get error that the "source file could not be read" (I think that this is because it is made for POSIX, but I'm not sure).
Any help would be appreciated!
(Also, just so you know, I'm very new to programming and C++)
I managed to do this in C#. Here is the code (I think the C++ code would be quite similiar):
var arguments = "-jar -Xms" + Settings.ServerStartInfo.InitialRam + "M -Xmx" +
Settings.ServerStartInfo.MaximumRam + "M \"" + Settings.ServerStartInfo.FileName +
"\" -nojline" + Settings.ServerStartInfo.Arguments;
var processStartInfo = new ProcessStartInfo
{
FileName = "javaw.exe",
Arguments = arguments,
CreateNoWindow = true,
ErrorDialog = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = true,
StandardOutputEncoding = Encoding.UTF8,
StandardErrorEncoding = Encoding.UTF8,
UseShellExecute = false,
WorkingDirectory = Settings.ServerStartInfo.WorkingDirectory
};
Process = new Process { StartInfo = processStartInfo };
Process.OutputDataReceived += ServerOutputHandler.ServerOutputReceived;
Process.ErrorDataReceived += ServerOutputHandler.ServerOutputReceived;
Process.Start();
Process.BeginOutputReadLine();
Process.BeginErrorReadLine();
Process.WaitForExit();
Process.Start();
For more info, please take a look here: https://servercrafter.codeplex.com/SourceControl/latest#ServerCrafter/ServerCrafter.ClassLibrary/ClassLibrary/Server/Server.cs