dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Running silent installation with CreateProcess

  1. #1
    Join Date
    Jul 2015
    Posts
    11

    Running silent installation with CreateProcess

    Hi guys,
    I am trying to create a silent process with CreateProcess API. I have yet succeeded to do so. So i ask for your help, which is kindly appreciated.
    Code:
    DWORD RunSilent(const char* strFunct, const char* strstrParams)
    {
    	STARTUPINFOA StartupInfo;
    	PROCESS_INFORMATION ProcessInfo;
    	char Args[4096];
    	char *pEnvCMD = NULL;
    	char *pDefaultCMD = "CMD.EXE";
    	ULONG rc;
    
    	memset(&StartupInfo, 0, sizeof(StartupInfo));
    	StartupInfo.cb = sizeof(STARTUPINFO);
    	StartupInfo.dwFlags = STARTF_USESHOWWINDOW;
    	StartupInfo.wShowWindow = SW_HIDE;
    
    	Args[0] = 0;
    
    	pEnvCMD = getenv("COMSPEC");
    
    	if (pEnvCMD){
    
    		strcpy(Args, pEnvCMD);
    	}
    	else{
    		strcpy(Args, pDefaultCMD);
    	}
    
    	// "/c" option - Do the command then terminate the command window
    	strcat(Args, " /c ");
    	//the application you would like to run from the command window
    	strcat(Args, strFunct);
    	strcat(Args, " ");
    	//the parameters passed to the application being run from the command window.
    	strcat(Args, strstrParams);
    	strcat(Args, " /S  /norestart /q");
    
    	if (!CreateProcessA(NULL, Args, NULL, NULL, FALSE,
    		CREATE_NEW_CONSOLE,
    		NULL,
    		NULL,
    		&StartupInfo,
    		&ProcessInfo))
    	{
    		return GetLastError();
    	}
    
    	WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    	if (!GetExitCodeProcess(ProcessInfo.hProcess, &rc))
    		rc = 0;
    
    	CloseHandle(ProcessInfo.hThread);
    	CloseHandle(ProcessInfo.hProcess);
    
    	return rc;
    
    }
    I also tried escaping the backslashes it didn;t help....Perhaps it needs something specific.

    Thanks.

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,605

    Re: Running silent installation with CreateProcess

    What do you mean by silent? by installation?

    In case some well known installer system is implied, you have to refer to correspondent documentation.

    As for your code, it's not clear what sort of issue you are facing, as you provide no description of what happens under what circumstances, and what is expected to happen. Just asking for help hardly would work for you in this forum.
    Best regards,
    Igor

  3. #3
    Join Date
    Jul 2015
    Posts
    11

    Re: Running silent installation with CreateProcess

    Hi For instance, i wanted to install Dropbox silently. By silently , i mean just execute the process , So user does not see any windows about "Installing ........" or "Downloading......".
    I want to be able to open a start application of the DropBox without him the installation windows. Is it possible?

    Thanks

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,248

    Re: Running silent installation with CreateProcess

    Quote Originally Posted by NirDemchog View Post
    Hi For instance, i wanted to install Dropbox silently. By silently , i mean just execute the process , So user does not see any windows about "Installing ........" or "Downloading......".
    I want to be able to open a start application of the DropBox without him the installation windows. Is it possible?

    Thanks
    It depends if the dropbox installation can be run silently.

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,605

    Re: Running silent installation with CreateProcess

    Quote Originally Posted by NirDemchog View Post
    Hi For instance, i wanted to install Dropbox silently. By silently , i mean just execute the process , So user does not see any windows about "Installing ........" or "Downloading......".
    I want to be able to open a start application of the DropBox without him the installation windows. Is it possible?
    Well, I think a correct question is if it is acceptable for your users.

    A standard security policy implies user is informed about any change done in the system, and explicitly confirms that change. Any software playing dirty tricks with installations, like invisible or looking-innocent-but-bundled-with-sneaky-third-parties or mimic-something-else setups should be expelled as soon as possible, that's what I think about this sort of malware.
    Best regards,
    Igor

  6. #6
    Join Date
    Jul 2015
    Posts
    11

    Re: Running silent installation with CreateProcess

    In the end i solved it by ShellExecuteEx , and of course i needed to pass right arguments to the installer.
    Thanks everyone who answered.

  7. #7
    Join Date
    Jul 2015
    Posts
    11

    Re: Running silent installation with CreateProcess

    By the way,
    I believe if you install some weird stuff then maybe, but here user is himself clicking on the dropbox and i just wanted to install it silently.
    I dont install something the user himself does not want.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)