I have a requirement where i need to install a application using a batch file.
when i run this batch file it asks for inputs and that batch file internally calls a powershell script which ask the inputs, if i hit a enter key for some inputs it takes the default values.
Can any one let me know how to store all inputs in a file and pass it to a batch file and it should also support the same for powershell script as well as the default values.
BATCHFILE.cmd
#echo off
setlocal EnableDelayedExpansion
set scriptsPath=%~dp0
set scriptsPathShort=%~dps0
set psPath=%windir%\System32\WindowsPowerShell\v1.0\powershell.exe
:params
set Path=%~1
set psVersion=0
if "!psVersion!" == "2.0" "!psPath!" -version !psVersion! -command "!scriptsPathShort!install\install-driver.ps1" '!Path!' '****'
if not !errorlevel! == 0 goto error
goto end
install-driver.ps1
param
(
[string] $scriptsBasePath = $(throw "Missing parameter: scriptsBasePath"),
[string] $Path = $(throw "Missing parameter: packagePath"),
[string] $packageRootFolder = $(throw "Missing parameter: packageRootFolder")
)
$configFileName = "install.config"
**install.config**
<Param name="ClientDir" required="1"
label="Client Directory"
desc="Choose a unique name which will be used by the application to create folder in which client files will be stored" />
<Param mode="adv" name="lPswdEncryptionMode" required="1" defaultValue="2"
label="Password Encryption Mode" />
<Param componentType="webserver" name="WebsiteName" required="1" defaultValue="Default Web Site"
label="Website Name"
desc="Enter site name under which the website component will be installed" cloud="1" />
This is only piece of code just to have a idea .
it calls a config file where i have few parameters.
Can any one please let me know how to pass the variables ?
Here is how I gather variables from my config/ini files into powershell.
$SETTINGS = Get-Content .\install.config
$scriptsBasePath = $SETTINGS[0]
$Path = $SETTINGS[1]
$packageRootFolder = $SETTINGS[2]
If install.config is not in the same directory, substitute the full path.
Related
I am been trying to search online for a solution but due to lack of knowledge in HP ALM I am not able to search proper hit tags
Set RunFactory = tsTest.RunFactory
Set obj_theRun = RunFactory.AddItem(CStr(testrunname))
obj_theRun.Status = sExecutionStatus '"Passed" '-- Status to be updated
obj_theRun.Tester = strTesterName
Getting error in this line object does not support obj_theRun.Tester
I just want to update the Tester column(Not Responsible tester) in Test set via vbscript. Please refer to the attached image at the very last column (TesterAny help is appreciated. Thank you in advance.
The documentation for ALM says the Tester Name can be specified by passing an array as the argument to AddItem.
https://admhelp.microfocus.com/alm/api_refs/ota/Content/ota/topic8805.html?Highlight=tester
An array consisting of the following elements:
Name - The name of the run (string. required).
Tester - The name of the user responsible (string. optional)
Location - The host name (string. optional). The default is the host name of the current machine
So change your code to this:
Set runFactory = tsTest.RunFactory
Dim newRunArgs(3)
newRunArgs(0) = testrunname ' `testrunname` is already a string so you don't need CStr.
newRunArgs(1) = "tester name goes here"
Set newRunArgs(2) = Nothing
Set newRun = RunFactory.AddItem( newRunArgs )
newRun.Status = sExecutionStatus '"Passed" '-- Status to be updated
How do I take the user input and let that be the directory for a text file?
I tried putting quotes around the ("Inp.txt") but this doesn't read the actual user input.
Set oFSO = CreateObject("Scripting.FileSystemObject")
Inp= InputBox("Please Enter Desired Location of Log File:")
If Inp= "" Then
Set oTF = oFSO.CreateTextFile("C:\Old Files.txt")
Else
Set oTF = oFSO.CreateTextFile(Inp.txt)
End If
I want to prompt the user for an input asking where they'd like to place their created text file; if left blank i would set it to a default location. I tried setting an inputbox prompt but when i use that as the text file location I receive an "Object Required" runtime error.
Build a complete path from the directory and a file name:
Set oTF = oFSO.CreateTextFile(oFSO.BuildPath(Inp, "output.txt"))
I would recommend letting the users browse for the folder, though.
Set app = CreateObject( "Shell.Application" )
Set d = app.BrowseForFolder(0, "Select Folder", 1, "C:\")
If d Is Nothing Then
Inp = "C:\"
Else
Inp = d.Self.Path
End If
Set oTF = oFSO.CreateTextFile(oFSO.BuildPath(Inp, "output.txt"))
I have this below vbscript to get one of the details of a file (we get by View->Choose Details in active folder window) which will retrieve Title detail/property of that file.
folder = "D:\StrongBox\Desktop\CSS The Complete Guide\01 Getting Started"
filename = "001 Introduction.mp4"
Set ShellObj = CreateObject("Shell.Application")
Set FolderObj = ShellObj.Namespace(folder)
MsgBox FolderObj.GetDetailsOf(FolderObj.Parsename(filename), 21)
How to set the detail of the the file?
I could not find a function like SetDetailsOf.
I am using UFT 12.5. During run time it opens excel and word. Then it writes some data in the both files. After that, I would like to save both files with a new name and then password protected. I need to be able to enter password manually to open it. So far, I have written the below code and I getting an error at the last line.
Set ExcelObj = createobject("excel.application")
ExcelObj.Visible = true
Set ExcelFile = ExcelObj.Workbooks.Open (file)
Set ScripSheet = ExcelFile.Worksheets("Scripts")
ScripSheet.Cells(1,1) = "Passed"
ExcelFile.SaveAs mm1, "ttt"
Please advise on how I can save word and excel files with a password using UFT.
Thanks.
You need to pass correct parameters with SaveAs method. Check this link for more info.
Here is the working code that you can try:
file = "File path with file name"
newfile = "File path with new file name"
Set ExcelObj = createobject("excel.application")
ExcelObj.Visible = true
Set ExcelFile = ExcelObj.Workbooks.Open (file)
Set ScripSheet = ExcelFile.Worksheets("Scripts")
ScripSheet.Cells(1,1) = "Passed"
ExcelFile.SaveAs newfile, , "test"
ExcelFile.Close
ExcelObj.Quit
UPDATE
Per comments from OP
If you want to save file with ReadOnly, you have to use WriteResPassword parameter this way:
ExcelFile.SaveAs newfile, , , "test"
Note that I've two empty parameters for FileFormat and
Password respectively.
This way it will ask for password to open the file in write mode and if you won't provide the password, file will be opened in ReadOnly
mode.
Check the link that I've mentioned.
My custom defined protocol (phpfile) lets me open php-files in an editor through the browser. The only problem is, it gives the full url, that is different in each browser, i've seen:
phpfile:/[file]
phpfile:/[file]/
phpfile://[file]/
phpfile://[file]
All these need to be converted to just [file]. The problem is that I get a syntax error. What is the correct syntax?
set var=%1
if("%var:~0,9%"=="phpfile:/")
{
set url = %var:~9%
}
else
{
set url = %var:~10%
}
if(%var:-1,1% == "/")
{
url = %url:~0,-1%
}
START "" "C:\Program Files (x86)\NuSphere\PhpED\7.0\phped.exe" url
=== Edit ===
I now have the following, but it is adding "" at the end of the url
SETLOCAL enabledelayedexpansion
set var=%1
if %var:~0,9%=="phpfile:/" (
set url = %var:~9%
) else (
set url = %var:~10%
)
if "%var:~-1%"=="\" (
set url = %url:~0,-1%"
)
if "%var:~-1%"=="/" (
set url = %url:~0,-1%"
)
START "" "C:\Program Files (x86)\NuSphere\PhpED\7.0\phped.exe" %url:"=%
That's because you wrote some horrible bastard between batch files and C but certainly no language that is in use anywhere.
Try the following:
setlocal enabledelayedexpansion
set "var=%~1"
if "!var:~0,9!=="phpfile:/" (
set "url=!var:~9!"
) else (
set "url=!var:~10!"
)
if "!var:-1,1!"=="/" (
set "url=!url:~0,-1!"
)
START "" "C:\Program Files (x86)\NuSphere\PhpED\7.0\phped.exe" "!url!"
Delayed expansion was used primarily to deal better with some characters that cause trouble in batch files. Generally though, I wonder how you would ever have expected your code to work.
There were quite a few problems in your code, this should fix things:
set var="%1"
if %var:~0,9%=="phpfile:/" (
set url="%var:~9%"
) else (
set url="%var:~10%"
)
if "%var:-1,1%"=="/" (
set url="%url:~0,-1%"
)
START "" "C:\Program Files (x86)\NuSphere\PhpED\7.0\phped.exe" url
You can check the syntax of batch file commands using help <command>. IF statements don't use curly braces, or require round brackets around the conditional statement.