.PIF With ? Allowed for a Variable Request - batch-file

Up until now I have been using the .PIF shortcut with "?" to call for a variable that is then used in a batch file to produce specific results. We have over project 10,000 folders, and the JobFind.PIF tool really satisfied a quick search. It is like a moving or floating Shortcut.LNK to any one folder in the larger directory.
Program Line Call Inside JobFind.PIF
S:\YoursTruly\JobFind\JobFind.bat ?
JobFind.bat Contents Where %1 = ?
explorer "P:\SDIT_L~1\Projects\000030%1"
Is there a simple replacement for my olde fashion JobFind.pif tool?
Thank you,
GPB

You could replace it with either a command-line or GUI VBScript. Here's an example:
strJob = InputBox("Enter the job number:")
With CreateObject("WScript.Shell")
.Run "explorer.exe P:\SDIT_L~1\Projects\000030" & strJob
End With

Related

Batch File Calls VB Script & Passes Filename as String Only

I have a batch file that calls a VB Script file. This VB Script comes from MS Office Suite and is located in the Installed Folder. My file calls the VB Script and pipes it to a file using the > symbol. This works if your redirect is a string. I was wondering how to redirect to a file using a variable.
I'm only including a small fraction of the code showing how I want it to work.
This, as written, works. However I want my batch file to use a variable instead of the text in quotes. In fact, my batch file creates the path depending on where the batch file is located.
::Create file and display on screen
Echo Writing Information to File: "OfficeStatus.txt"
Call cscript ospp.vbs /dstatus > OfficeStatus.txt
Echo.
When written as shown below, it does not work:
::Create file and display on screen
Echo Writing Information to File: "OfficeStatus.txt"
Call cscript ospp.vbs /dstatus > %_sLogFile%
Echo.
I don't know if the issue is because of the redirect not able to handle a variable or not. An example of what might be in the variable:
_sLogFile=E:\UserName\Documents\Status\OfficeStatus.txt.
Any thoughts would be great.
The variable, by the way, correctly contains the path and filename... so that's not the issue.
it does not work means did not do what I expected and unfortunately does not tell us what it did do.
Did it crash the system? Create an error message (If so, what message)? Create an output file in an unexpected place??
Personally, I'd suspect what you have concealed as username. Without knowing precisely what that text is, we start guessing, which isn't a logical approach. It doesn't have to be the real username, substitute Fred Bloggs for the real name to mask it if necessary.
I believe that username may either be %username% to retrieve the name from the system, or a real literal. The problem with this is that such names often contain spaces, you'd need to "Enclose the full filename in quotes".
See - had you told us _sLogFile=E:\Fred Bloggs\Documents\Status\OfficeStatus.txt it would all have been a lot clearer - presuming that my guess as to the cause of the problem is correct.
Perhaps you should look for files named like E:\Fred which is where the expected output may have ended up.

Change an environment variable in between Jenkins build steps

I have a Jenkins job with a string parameter called MyPath, a groovy script build step and then a batch command build step.
If I kicked off a job so that the value of MyPath is "C:\Temp\", I want the groovy script to change the value of MyPath to be "C:\Temp\3.4\setup.exe" and then I want to use the batch file to execute MyPath.
I know I can launch a process from groovy and that I can perform my groovy logic in batch, it would just be nice if I could pass variables between build steps.
To use a parameter in groovy you have to use the library to resolve it (below). Is there a method that can set it?
def path = build.buildVariableResolver.resolve("MyPath");
Something like this would be perfect if it existed:
buildVariableChanger.change("MyPath") = "C:\3.4\setup.exe"
I have also looked into the EnvInject plugin but from what I understand it does not support what I want to do.
Thanks.
I don't think it is possible since field value for StringParameterValue.class is final: http://javadoc.jenkins-ci.org/hudson/model/StringParameterValue.html
The solution may be creating other parameter in groovy script
import hudson.model.StringParameterValue
import hudson.model.ParametersAction
def newPath = build.buildVariableResolver.resolve("MyPath") + "3.4\\setup.exe"
build.addAction(new ParametersAction (new StringParameterValue ('path2', newPath)))
and then use parameter path2 in batch command
Why don't you simply pass a variable to your batch? You could start the batch from your first script instead of starting it with an own build step. Just call it with yourscript.bat C:\3.4\setup.exe. You can access the argument with %1. If you insert the line %1 into your bat file it will execute C:\3.4\setup.exe.
One option should be to use the SETX Windows command to set the value of user (or system) environment variable.
If you set this variable in your Groovy step, then the batch step should be able to use it.

Passing an argument into a VBS script which passes into a batch file

I have a legacy application which doesn't support utilizing the default applications defined in windows which requires that I specify a specific an executable for a file format to be opened within the application. Since Microsoft no longer includes MODI with Office by default I have been looking at using launching Windows Picture Viewer for .TIF, .TIFF, & .BMP files since it is built into Windows; however Microsoft does not have a direct executable for Windows Picture Viewer which can be called forcing me to create a script which executes the command which calls for Windows Picture Viewer to execute. After research the only way I have been able to call the application to open a specific file is by creating a batch file such as below:
GIFTS.BAT
rundll32.exe C:\WINDOWS\system32\shimgvw.dll,ImageView_Fullscreen %~1
If I execute the above code such as GIFTS.BAT "C:\Example Directory\Sample File.tif" from a command prompt or from the application launches and the Sample File.tif opens without a problem; however a command prompt opens along with the file when launching from the application.
Upon which I tried to create a vbscript to hide the batch file from executing however I can't seem to pass my argument if the argument has a "space" within the argument.
GIFTS.VBS
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run """C:\GIFTS.BAT"" " & WScript.Arguments.Item(0), 0
Set WshShell = Nothing
If I try to execute the VBScript from a command prompt such as GIFTS.VBS "C:\Example Directory\Sample File.tif" the application never launches and the command prompt returns no message or error. If I simplify the execute command (removing spaces to GIFTS.VBS "C:\Sample_File.tif" the application launches as well as the file Sample_File.tif is displayed and there is no command prompt displayed when the application executes the VBScript.
My question is how can I pass an argument into the VBS script that in return passes the the batch file when the argument contains spaces (which there is always going to be spaces since the argument will be a file name and path)?
There might be an easier approach to what I want to accomplish; however I am looking for a solution that Windows 7 - 8.1 can utilize with no additional software to install or manage on each workstation. The batch files works great I just need to be able to hide the command prompt that opens along with the application as my end users won't know what to do with it.
Thanks!
Sometimes, nested levels of escaping characters requires intimate knowledge of the undocumented behavior of CMD or some voodoo. Another way to attack the problem is to guarantee that you won't have any spaces in the name of the file. Windows has a concept of a short path (no spaces or special chars) for which every existing file has a unique one.
Here's a modified version of your program for which invoked subcommand doesn't need quotes around the file name.
Set WshShell = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Set fsoFile = fso.GetFile(WScript.Arguments.Item(0))
WshShell.Run """c:\GIFTS.BAT"" " & fsoFile.ShortPath, 0
Set WshShell = Nothing
You may wish to add your own error checking. The specified file must exist in order for the GetFile() command to succeed.

Creating a shortcut for a file using MATLAB

I would like to create a shortcut to an existing image file using MATLAB routines. My goal is to have a shortcut in a folder that i specify, to the image from another folder that i specify (for organizing purposes).
What i want to achieve is the same thing that happens when i right click on the image icon and select 'create shortcut' option, only changing the target directory for the created shortcut.
I have about twenty thousand images to orginize so copying the files instead is not an option(it takes a really long time).
I will really appreciate any help. Thank you!
Why don't you try to add the path (addpath) and then use directly Matlab behaves as if the images are in the same folder. Check here
You could call a VBS script from MATLAB.
For VBS script see: http://technet.microsoft.com/en-us/library/ee156583.aspx
Then write a wrapper function in MATLAB calling the VBS script with a system command:
cmd=sprintf('cscript //nologo "%s" %s "%s" "%s" "%s" "%s" "%s"',...
vbsfile,name,targetpath,workingdir,iconlocation,hotkey,desc);
system(cmd);

Write a batch script to edit text in a .cs file

I wonder if anyone knows how to write a batch script to edit some text in a .cs file.
What I want to do is change "AssemblyVersion("1.0.0.0")" "AssemblyVersion("1.0.0.x")" where x++ for every time the job in jenkins is being built.
Best Regards Jan
Do you want to use only a batch script for this? You could also use Execute Groovy Script option and write some simple groovy script to achieve this
file = new File("folder/path/myfile.cs")
fileText = file.text;
fileText = fileText.replaceAll(srcExp, replaceText);
file.write(fileText);
You can also use the availabe environment variables from your jenkins job to construct your replace text. These variables will be present at /env-vars.html
Stay away from "batch-file automation" - will only cause you grief.
(for a starter, different versions of Windows support a different set of batch-commands)
You should incorporate the build-number in the script as an Environment Variable -
use either the "built-in" %BUILD_NUMBER% parameter or set your own format with
the Formatted Version-Number Plugin .
If you do need to edit that 'CS' file, I suggest using either Perl or PowerShell.
Cheers

Resources