We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

lekfir
Posts: 130
Joined: Sun Feb 15, 2009 5:26 pm

Command line and Driver Start

1. What is the best way to start a Driver (Net Start %DriverName%) after I installed it?

2. What is the best way to run a command line (Probably as Custom Action?)

3. Is there a way that running a command line will keep the black console window hidden and will not be displayed to users?

4. Is it possible to run bat file as "File Attached to Installation" mode? (So the batch file will not exist in the Program folder)

Thanks!
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Command line and Driver Start

Hi,
1. What is the best way to start a Driver (Net Start %DriverName%) after I installed it?
You can either use "net start %DriverName" or you can use "sc start %DriverName". Either way works just fine.
2. What is the best way to run a command line (Probably as Custom Action?)
3. Is there a way that running a command line will keep the black console window hidden and will not be displayed to users?
To achieve this, you can use this script:

Code: Select all

'Usage:
'- Save this script as ExecuteBat.vbs
'- from the Custom Actions page, add a new Attatched Custom Action
'- select ExecuteBat.vbs from the Browse dialog
'- make sure the Source Type is set to "Visual basic script (*.vbs)
'- set the Function Name field to ExecuteBat
'- the Action Data field must be in this format:
'  <full path to .bat>|<.bat file's working directory>|< 0 for running hidden, 1 for running visible>
'   Example:
'   [MYPATH]mybat.bat | [WindowsVolume]Windows | 0
'- note that no quotation marks should be used

Function ExecuteBat()	
	Dim WindowStyle_Visible, objShell, result, actData, batfilename,workingdir,thirdparam, x
	
	'extracting the parameters
	result= Session.Property("CustomActionData")
	
	'splitting the parameters
	actData = Split(result,"|")
	
	batfilename = actData(0)  'first parameter is the full path to the bat
	workingdir = actData(1)    'second parameter is the working directory
	WindowStyle_Visible	= actData(2) 'third parameter, is the cmd window visible?
	
	'strip the additional spaces at the beginning and the end of the string
	workingdir = LTrim(workingdir)
	workingdir = RTrim(workingdir)	
		
	'creating the shell object
	set objShell = CreateObject("WScript.Shell")	
	
	'setting the current working directory
	objShell.CurrentDirectory  = workingdir
	
	'adding the required quotes
	batfilename = """"&batfilename&""""
	
	'running the bat file synchronously to avoid unexpected behavior due 
	'to interference with the install process 
	'this behavior can be overridden by selecting Asynchronous execution from Advanced Installer
	result = objShell.Run("cmd.exe /c "&batfilename&"" , WindowStyle_Visible,1)	
End Function
4. Is it possible to run bat file as "File Attached to Installation" mode? (So the batch file will not exist in the Program folder)
I am afraid this is not possible. You can however add your bat as temporary file from the "Files and Folders" page, then on the custom action used to launch the ExecuteBat script, set the Action Data to something like:

Code: Select all

[APPDIR]batman.bat |[APPDIR]|  0
Note that the second parameter need not necessarily be [APPDIR], it can be whatever working directory you like for your .bat file.

Regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
lekfir
Posts: 130
Joined: Sun Feb 15, 2009 5:26 pm

Re: Command line and Driver Start

Thnaks Gabriel,
Regarding question 1:
1. What is the best way to start a Driver (Net Start %DriverName%) after I installed it?

I meant, "What is the best way to start a Driver using (AdvancedInstaller) after I installed it?

Thks
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Command line and Driver Start

Hello,

To automatically start a service after installation simply:
- go to the Services page
- right click "Control Operations" and add a new "Control Operation"
- fill in the Service Name field with the name of your service
- Attached Component: In this field you can specify the component which will contain the control operation
- Select the appropriate control operations from the checkboxes
- pass arguments from the Arguments field if needed

Regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
lekfir
Posts: 130
Joined: Sun Feb 15, 2009 5:26 pm

Re: Command line and Driver Start

Hi Gabriel,
I did exactly the steps of the vbs but it didn't work.

I did a simple batch file that closes notepad.exe on uninstall. The file name is kill.bat and it was placed in [APPDIR] folder with ExecuteBat.vbs that contains the exact code you supplied:
Kill.bat: taskkill /im notepad.exe /f

The other settings:
Source Path:[APPDIR]ExecuteBat.vbs
Source Type: Visual basic script (*.vbs)
Function Name: ExecuteBat
Action Data: [APPDIR]kill.bat |[APPDIR]| 0
Execution Condition: (REMOVE="ALL")

Any idea?
Thanks!
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Command line and Driver Start

Hi,

The script should work correctly, i tested it again. Please note that the script must be set as an Attached Custom Action, and the Source Path is not property based. Once you set the source to say c:\ExecuteBat.vbs, the script will be included in the installer and run from there when called.

Also make sure that your kill.bat file is added as a temporary file.

Regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
lekfir
Posts: 130
Joined: Sun Feb 15, 2009 5:26 pm

Re: Command line and Driver Start

Thanks GabrielBarbu,
The script didn't work when it was in the Begin custom action and Execution Condition set to REMOVE="ALL"...

When I placed it in the Uninstall action, it worked!
lekfir
Posts: 130
Joined: Sun Feb 15, 2009 5:26 pm

Re: Command line and Driver Start

And how do I run a vbscript in hidden mode?
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Command line and Driver Start

Hello,
lekfir wrote:And how do I run a vbscript in hidden mode?
I am not sure what you mean by this.Can you give me more details? VBScripts are by default executed as hidden, without any user interface, unless you have specific commands like MsgBox in it that provide an interface to the script.

Regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
shoekell
Posts: 1
Joined: Fri Aug 28, 2009 10:35 pm

Re: Command line and Driver Start

I am trying to do a similar task as lekfir and I cannot get it to work. I am trying to install Apache and MySQL as a service after I move my files over. Both of these have to be installed as services in particular ways.
Here is the apache_installservice.bat file that installs the Apache service and starts it:

Code: Select all

@ECHO OFF & SETLOCAL
PUSHD %~dp0

ECHO Installing Apache as a service
xampp_cli.exe installservice apache

IF NOT ERRORLEVEL 1 (
    ECHO Now we start Apache :)
    xampp_cli.exe startservice apache
)

POPD
PAUSE
Here is the mysql_installservice.bat file to install and start MySQL as a service:

Code: Select all

@ECHO OFF & SETLOCAL
PUSHD %~dp0

ECHO Installing MySQL as a service
xampp_cli.exe installservice mysql

IF NOT ERRORLEVEL 1 (
    ECHO Now we start MySQL :)
    xampp_cli.exe startservice mysql
)

POPD
PAUSE
I have placed both .bat files into the "Application Folder" in the "Files and Folders" window in Advanced Installer as temporary files.

Screenshot of Files and Folders: http://www.basicengineeringpc.com/advan ... olders.pdf

I am trying to call both of these files through the ExecuteBat.vbs file mentioned earlier in this thread. I have not been able to get it to work. Can you look over my settings in "Custom Actions" and let me know what I am doing wrong? Here is a screenshot of my "Custom Settings' screen: http://www.basicengineeringpc.com/advan ... ctions.pdf

Thanks.
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Command line and Driver Start

Hello,

I am not sure what is causing this behavior. Please send your .aip project file (or a stripped down version if it contains sensitive information) to support at advancedinstaller dot com so I can further investigate the problem.

Regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/
GabrielBarbu
Posts: 2146
Joined: Thu Jul 09, 2009 11:24 am
Contact: Website

Re: Command line and Driver Start

Hello,

I have recieved your aip file. I replaced the .bat files in your project with a test .bat file of my own. It is launched correctly. Perhaps your batch files are running but you didn't notice, since they are running hidden. I recommend you try setting the ExecutaBat's custom action data to:

Code: Select all

[APPDIR]apache_installservice.bat|[APPDIR]| 1
so you can check if the bat files really are running.

Regards,
Gabriel
Gabriel Barbu
Advanced Installer Team
http://www.advancedinstaller.com/

Return to “Common Problems”