Execute command line statement in installshield / installscript - installscript

How do I execute the following command in installscript during installation?
netsh.exe advfirewall firewall show rule name="PowerSI (Release ASI 16.64)" || NETSH.EXE advfirewall firewall add rule name="PowerSI (Release ASI 16.64)" dir=in action=allow program="d:\Cadence\HIM_asi1664\ASI\Update4\SpeedXP\SpeedXP Suite x64\PowerSI.exe" enable=yes profile=any description="d:\Cadence\HIM_asi1664\ASI\Update4\SpeedXP\SpeedXP Suite x64\PowerSI.exe"
Note that the above command contains the executable name i.e. netsh.exe twice and this is where the problem is. I tried LaunchAppAndWait first by using the whole command as the name of executable and passing an empty string as argument. Next I tried was passing the first netsh.exe as program name and the remaining text as argument. Both the approaches did not work.

Since the question is regarding InstallScript specifically, here's a simple function for this purpose.
// prototype void CmdExecute( STRING );
//---------------------------------------------------------------------------
// Function: CmdExecute
//
// Purpose: Asynchronusly execute a command line statement in the background
//
//---------------------------------------------------------------------------
function void CmdExecute( szCommand )
begin
LaunchApplication( "cmd.exe", "/C " + szCommand, "",
SW_HIDE, 0, LAAW_OPTION_NOWAIT );
end;
In your specific case, if you need to execute a series of commands, or if you run into other complications, I suggest using a batch file instead. If need be, you can write one on the fly (to have a pure installscript solution without adding files to the project), run it via LaunchApplication (or the variations of that) and then delete it afterwards.
As a nice little trick, I like to make such a batch file delete itself. How? At the end of it, add this:
cmd.exe /C timeout 30 >nul & del "%0" /q
This starts a separate process, so the batch file in no longer in use. The full 30 second delay isn't really necessary, but has proven to always work for me in the past. You can adjust that time, if you want it to hurry up and finish. The point is to make sure the batch can be deleted, which it can't be if it's in use.

Custom Action Wizard --> Launch an Exectuable --> Stored in the Directory table --> SystemFolder (as source)
Then for Target do: cmd /c "SOMETHING",
where SOMETHING is replaced with your command. The only thing you would need to worry about is escaping all of the double quotes.
Then sequence the action after "Cost Finalize" in the execute sequence, and you should be good.
Haven't fully tested it, but should work.

Related

Complete directory names using the end of the string on command completition

Let's say I have a directory with the following contents:
/Project.Presentation
/Project.Presentation.API
/Project.Presentation.Web
/Project.Presentation.Infra
/Project.Presentation.Util
I want to do this -> Project.Presentation: API and let it autocomplete to Project.Presentation.API. Inside Project.Presentation to type API and <tab>.
Is it possible to let zsh use this 'forgiving' way of ?
You're overcomplicating your solution.
If you want to execute a command with a file inside these directories, or just cd in one of these directories.
Just write cd (or other command) first, then press tab that will complete Project.Presentation. then you can either write API or write A and press tab.
By the way, you can have a way to navigate through the possibilities with an extra tab key.
Read man zshoptions for to discover options available in zsh.

Disabling BCD testsigning option using registry

My code should disable testsigning BCD option using Windows registry. The same as command line bcdedit -set testsigning off.
I can't do shellexecute with cmd. I found one Testsigning reference in registry, in HKLM\SYSTEM\ControlSet001\Control\SystemStartOptions value, but this value contains current kernel run options, not options for next start.
So, I can't use it.
I found that testsigning option are saved in HLKM\BCD00000000\Objects\{%GUID%}\Elements\16000049, but this GUID is different on different PC's.
How I could acquire it?
If you don't bother of activating it for all boot entries:
Enumerate all key names beneath "Objects"
Write your registry values in a loop into every found key name.
Using NT native API your approach could look something like the following pseudocode:
while(numEntries < index){
NtEnumerateKey(index++, &pGuidKeyname...);
RtlStringCbPrintfW(buf, %s, rootkey,pGuidKeyname);
NtSetValueKey(buf, "YES");
}

grunt updating options in one task so subsequent tasks can use them

I need to run grunt-bump which bumps the version number in the package.json, then run grunt-xmlpoke and update a config file with new version number.
So I have tried a couple of things. Inside the grunt.initConfig I run bump, then I run xmlpoke.
1) xmlpoke takes grunt.file.readJSON('package.json').version
or
2) after bump I run a custom task that adds the new version to a grunt option and xmlpoke takes a value of grunt.options("versionNumber")
In both of these versions the xml result is the pre-bump version. So xmlpoke is getting it's values before the tasks are run and the uses them when it's task is called. But I need it to take the value that is the result of a previous task.
Is there anyway to do this?
Ok, I have figured out the, somewhat obvious, solution.
Using grunt-bump you can update the package.config, you can also update the package.config that is often read into the variable pkg at the beginning of the initConfig. so in the setup of the bump task you specify
{
updateConfigs:['pkg']
}
Then in the xmlpoke I can do
{ xpath:'myxpath', value:'blablabla/<%=pkg.version%>'}
and this works. What I was doing before was
{ xpath:'myxpath', value:'blablabla/' + grunt.options.versionNumber}
where I had set the versionnumber in a previous task after the bump. Or
{ xpath:'myxpath', value:'blablabla/'+ grunt.file.readJSON('package.json').version}
neither of those worked. I guess I was just getting to smart for my own good as the <%= %> is the more common and typical way of accessing parameters from within the initConfig.
Anyway, there you have it. Or I have it.

How to get and set the default output directory in Robot Framework(Ride) in Run time

I would like to move all my output files to a custom location, to a Run directory created based on Date time during Run time. The output folder by datetime is created in the TestSetup
I have function "Process_Output_files" which will move the files to the Run folder(Run1,Run2,Run3 Folders).
I have tried using the argument-d and used the function "Process_Output_files" as suite tear down to move the output files to the respective Run directory.
But I get the following error "The process cannot access the file because it is being used by another process". I know this is because the Robot Framework (Ride) is currently using this.
If I dont use the -d argument, the output files are getting saved in temp folders.
c:\users\<user>\appdata\local\temp\RIDEfmbr9x.d\output.xml
c:\users\<user>\appdata\local\temp\RIDEfmbr9x.d\log.html
c:\users\<user>\appdata\local\temp\RIDEfmbr9x.d\report.html
My question is, Is there a way to get move the files to custom location during run time with in Robot Framework.
You can use the following syntax in RIDE (Arguments:) to create the output in newfolders dynamically
--outputdir C:/AutomationLogs/%date:~-4,4%%date:~-10,2%%date:~-7,2% --timestampoutputs
The above syntax gives you the output in below folder:
Output: C:\AutomationLogs\20151125\output-20151125-155017.xml
Log: C:\AutomationLogs\20151125\log-20151125-155017.html
Report: C:\AutomationLogs\20151125\report-20151125-155017.html
Hope this helps :)
I understand the end result you want is to have your output files in their custom folders. If this is your desire, it can be accomplished at runtime and you won't have to move them as part of your post processing. This will not work in RIDE, unfortunately, since the folder structure is created dynamically. I have two options for you.
Option 1: Use a script to kick off your tests
RIDE is awesome, but in my humble opinion, one shouldn't be using it to run ones tests, only to build and debug ones tests. Scripts are far more powerful and flexible.
Assuming you have a test, test2.txt, you wish to run, the script you use to do this could be something like:
from time import gmtime, strftime
import os
#strftime returns string representations of a date-time tuple.
#gmtime returns the date-time tuple representing greenwich mean time
dts=strftime("%Y.%m.%d.%H.%M.%S", gmtime())
cmd="pybot -d Run%s test2"%(dts,)
os.system(cmd)
As an aside, if you do intend to do post processing of your files using rebot, be aware you may not need to create intermediate log and report files. The output.xml files contain everything you need, so if you don't want to create superfluous files, use --log NONE --report NONE
Option 2: Use a listener to do post processing
A listener is a program you write that responds to events (x_start, x_end, etc). The close() event is akin to the teardown function and is the last thing called. So, assuming you have a function moveFiles() you simply need to create a listener class (myListener), define the close() method to call your moveFiles() function, and alert your test that it should report to a listener with the argument --listener myListener.
This option should be compatible with RIDE though I admit I have never tried to use listeners with the IDE.
At least you can write a custom run script that handles the moving of files after the test case execution. In this case the files are no longer used by pybot.

autohotkey wildcard read loop

I want one script to command several computers to break up a highly distributable workload. In order to distribute the workload I put half of the task labels in one file, and half of the tasks in another file that i distribute to the computers with google drive (which is why i need different file names). So C:\googledrive\task1.txt and C:\googledrive\task2.txt
The autohotkey command looks like:
loop, read, c:\googledrive\task*.txt
But instead of reading task1.txt, it appears to try to read "task*.txt" as a literal file name, fails, and ends the loop.
Ideas? Thanks.
OK, tried ensuring everything was running with administrator rights (they are) and ensured that the files exist (they do) and no typos in the file path (everything good there). Still wont actually read the file.
There is one bit that I didn't include in the original post part of the file name is actually a variable, so the loop command is actually like:
loop, read, c:\googledrive\%task%*.txt
I just figured that bit was inconsequential.
If i save a different script for each computer, i can go ahead and replace the wildcard with the actual bit, and it works.
so... Im just going to name each file with the computer's name in the file, and change the command to:
loop, read, c:\googledrive\%task%%A_ComputerName%.txt
I do it this way....
Loop, C:\Temp\Source\*.txt ; Lists the next file as A_LoopFileName
{
Loop, read, C:\Temp\Source\%A_LoopFileName% ; process current file
{
IfInString, A_LoopReadLine, abc
{
.......
}
}
}

Resources