I have a prob calling SetBiosSetting method using WMIC (and also C#)
wmic /namespace:\root\wmi path Lenovo_SetBiosSetting call SetBiosSetting "SecurityChip,Active"
wmic /namespace:\root\wmi path Lenovo_SetBiosSetting call SetBiosSetting SecurityChip,Active
wmic /namespace:\root\wmi path Lenovo_SetBiosSetting call SetBiosSetting ("SecurityChip,Active")
that gives "Invalid Number of Parameters." error, but why ?
Lenovo BIOS Deployment Guide: http://download.lenovo.com/ibmdl/pub/pc/pccbbs/thinkcentre_pdf/hrdeploy_en.pdf
Any Idea ?
I cant use VBS or PowerShell ...
Thanks,Martin
Try this in C#:
ManagementScope scope = new ManagementScope(#"\\.\root\wmi");
//
// Make change(s)
//
SelectQuery queryRead = new SelectQuery("SELECT * from Lenovo_SetBiosSetting");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, queryRead))
{
using (ManagementObjectCollection queryCollection = searcher.Get())
{
foreach (ManagementObject queryItem in queryCollection)
{
ManagementBaseObject inParams = queryItem.GetMethodParameters("SetBiosSetting");
inParams["parameter"] = "WakeOnLAN,Disable";
ManagementBaseObject outParams = queryItem.InvokeMethod("SetBiosSetting", inParams, null);
string result = outParams["return"] as string; // "Success"
}
}
}
//
// Commit to BIOS
//
queryRead = new SelectQuery("SELECT * from Lenovo_SaveBiosSettings");
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, queryRead))
{
using (ManagementObjectCollection queryCollection = searcher.Get())
{
foreach (ManagementObject queryItem in queryCollection)
{
ManagementBaseObject inParams = queryItem.GetMethodParameters("SaveBiosSettings");
inParams["parameter"] = "";
ManagementBaseObject outParams = queryItem.InvokeMethod("SaveBiosSettings", inParams, null);
string result = outParams["return"] as string; // "Success"
}
}
}
The PowerShell for this is:
(gwmi -class Lenovo_SetBiosSetting -namespace root\wmi).SetBiosSetting("WakeOnLAN,Disable")
I arrived at this post trying to find a way to use WMIC to get all the objects in the Lenovo_BiosSetting class. Your syntax got me on the right track. I had to change your WMIC query to this:
wmic /namespace:\\root\wmi path Lenovo_BiosSetting get
(Note the double back slash)
Related
Katalon is popular in automation testing. I have already used it in our project and it works amazingly.
Now, What I want to achieve is to create a test case where it opens a terminal (using mac) and type in some commands to run it like for example:
cd /documents/pem/key.pem
connect to -my server via SSH#method
sudo su
yum install php7
yum install mysql
You are not alone, and with custom keywords you can achieve what you want. Here is an example showing a test of a command line app. You could do the same thing to call any command line script you wish. Think of a runCmd keyword, or a runCmdWithOutput to grab the output and run various asserts on it.
#Keyword
def pdfMetadata(String input) {
KeywordUtil.logInfo("input: ${input}")
def csaHome = System.getenv("CSA_HOME")
def cmd = "cmd /c ${csaHome}/bin/csa -pdfmetadata -in \"${projectPath}${input}\"";
runCmd(cmd)
}
def runCmd(String cmd) {
KeywordUtil.logInfo("cmd: ${cmd}")
def proc = cmd.execute();
def outputStream = new StringBuffer();
def errStream = new StringBuffer()
proc.waitForProcessOutput(outputStream, errStream);
println(outputStream.toString());
println(errStream.toString())
if(proc.exitValue() != 0){
KeywordUtil.markFailed("Out:" + outputStream.toString() + ", Err: " + errStream.toString())
}
}
You can then use this in a test case:
CustomKeywords.'CSA.pdfMetadata'('/src/pdf/empty.pdf')
Here is another custom keyword! It is takes the file name and path, and if you don't give it a path, it search for the file in the project root directory. It export the batch file's output in a batch_reports folder in your project folder, you need to create that in advance.
#Keyword
def runPostmanBatch(String batchName , String batchPath){
// source: https://www.mkyong.com/java/how-to-execute-shell-command-from-java/
String firstParameter = "cmd /c " + batchName;
String secondParameter = batchPath;
if (batchPath == ""){
secondParameter = RunConfiguration.getProjectDir();
}
try {
KeywordUtil.logInfo("Executing " + firstParameter + " at " + secondParameter)
Process process = Runtime.getRuntime().exec(
firstParameter , null, new File(secondParameter));
StringBuilder output = new StringBuilder();
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
output.append(line + "\n");
}
int exitVal = process.waitFor();
Date atnow = new Date()
String now = atnow.format('yy-MM-dd HH-mm-ss')
String report_path = RunConfiguration.getProjectDir() + "/postman_reports/" + RunConfiguration.getExecutionSourceName() + "_" + now + ".txt"
BufferedWriter writer = new BufferedWriter(new FileWriter(report_path));
writer.write(output.toString());
writer.close();
KeywordUtil.logInfo("postman report at: " + report_path)
if (exitVal == 0) {
println("Success!");
println(output);
KeywordUtil.markPassed("Ran successfully")
} else {
KeywordUtil.markFailed("Something went wrong")
println(exitVal);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
I've done some research. I did not found any resources or any people that is looking for the same thing I am. I think this is officially, No. The answer to this is, it is not possible.
It is possible to run Katalon Studio from the command line.
There's a short tutorial here.
And it will be possible to override Profile Variables via command line execution mode from v5.10 (currently in beta).
An example given on Katalon forum is:
Simply pass the parameters in command line using: -g_XXX = XXX
Below is an example of override an URL variable:
-g_URL=http://demoaut.katalon.com
I'm trying to figure out how to call windows camera UI from a windows form.
I did this and it does compile:
Public Function ShootPicture() As StorageFile
Dim captureUI As New CameraCaptureUI
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg
captureUI.PhotoSettings.AllowCropping = False
Dim GetPhotoTask As Task(Of StorageFile) = captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo)
GetPhotoTask.Wait() ' Blocks current thread until CaptureFileAsync task completes'
Dim result As StorageFile = GetPhotoTask.Result
Return result
End Function
But there is a 'System.InvalidCastException' execution error on .capturefileAsync() : type 'System._ComObject' cannot be casted as 'System.threading.tasks.task'
Would anyone have any idea on how to fix this? Thanks
If it can help here is the c# code translation:
public StorageFile ShootPicture()
{
CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
captureUI.PhotoSettings.AllowCropping = false;
Task<StorageFile> GetPhotoTask = captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
GetPhotoTask.Wait();
// Blocks current thread until CaptureFileAsync task completes
StorageFile result = GetPhotoTask.Result;
return result;
}
CaptureFileAsync returns an IAsyncOperation, so try using await instead of a Task:
Dim result As StorageFile = Await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo)
I have a report that is hosted in SQL Server 2012 SSRS and it executes fine through the browser. I am trying to run it using WCF as a Service Reference for the SSRS 2005 asmx from a ASP.Net web project and return it as a PDF using the ReportExporter.Export() method; however, it is not returning a result at all and the warnings array is empty. So, how can I troubleshoot the process to see where the difficulty is? I did not find any errors in the SSRS Log file even when I set it to verbose; nor did I find any errors in the standard SQL Log.
Here is my code:
NOTE: the call ReportExporter.Export(..) is to a method that encapsulates the execution of the webServiceProxy to the Service Reference.
{
IList<SSRS_Reports.ParameterValue> parameters = new List<SSRS_Reports.ParameterValue>();
parameters.Add(new SSRS_Reports.ParameterValue { Name = "paramId", Value = _paramId.ToString() }); }
byte[] result = null;
string extension = string.Empty;
string mimeType = string.Empty;
string encoding = string.Empty;
string reportName = "/baseFolder/ReceiptReport";
SSRS_Reports.Warning[] warnings = null;
string[] streamIDs = null;
string uN = ConfigurationManager.AppSettings["rptUName"].ToString();
string uP = ConfigurationManager.AppSettings["rptPWD"].ToString();
string uD = ConfigurationManager.AppSettings["rptDomain"].ToString();
//NOTE: the call "ReportExporter.Export(..) is to a method that encapsulates the execution of the webServiceProxy to the Service Reference.
ReportExporter.Export("ReportExecutionServiceSoap",
new System.Net.NetworkCredential(uN, uP, uD),
reportName,
parameters.ToArray(),
ExportFormat.PDF,
out result,
out extension,
out mimeType,
out encoding,
out warnings,
out streamIDs);
if (result != null)
{
//create a file and then show in browser
_mPDFFile = randomName() + ".pdf";
_mPDFPath = HttpRuntime.AppDomainAppPath + "\\pdf\\" + _mPDFFile;
//clear files older than today
Lib.FileManager.ManageFiles(HttpRuntime.AppDomainAppPath + "\\pdf", "*.pdf", -1);
if (File.Exists(_mPDFPath))
{
File.Delete(_mPDFPath);
}
FileStream stream = File.Create(_mPDFPath, result.Length);
stream.Write(result, 0, result.Length);
stream.Close();
return true;
}
}
I want to know how to interact with shell from Mono and I can't seem to find very much information about this. For example, I want to return the output of "ls" and stick it into a variable - Is this even possible?
Here's what I have so far:
var proc = new Process();
proc.StartInfo.FileName = "ls";
proc.Start ();
proc.Close ()
It is possible to get the shell output. Please try the following -
Process p = new Process();
p.StartInfo = new ProcessStartInfo("/bin/ls", "-l")
{
RedirectStandardOutput = true,
UseShellExecute = false
};
p.Start();
p.WaitForExit();
//The output of the shell command will be in the outPut variable after the
//following line is executed
var outPut = p.StandardOutput.ReadToEnd();
I'd like to get the target information from a shortcut file using my silverlight OOB app, so I'm going to make the following code to work in my silverlight OOB. It seems I have to used P/Invoke to use Shell32.dll, but I'm not sure how I can use Folder, FolderItem, and ShellLinkObject? Most references explain how I can use the functions in the .dll using P/invoke:( Please give me any comments or sample code/links:)
public string GetShortcutTargetFile(string shortcutFilename)
{
string pathOnly = Path.GetDirectoryName(shortcutFilename);
string filenameOnly = Path.GetFileName(shortcutFilename);
Shell32.Shell shell = new Shell32.ShellClass();
Shell32.Folder folder = shell.NameSpace(pathOnly);
Shell32.FolderItem folderItem = folder.ParseName(filenameOnly);
if (folderItem != null)
{
Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
MessageBox.Show(link.Path);
return link.Path;
}
return String.Empty; // Not found
}
I found a solution.
public string GetShortcutTargetFile(string shortcutFilename)
{
string pathOnly = System.IO.Path.GetDirectoryName(shortcutFile);
string filenameOnly = System.IO.Path.GetFileName(shortcutFile);
dynamic shell = AutomationFactory.CreateObject("Shell.Application");
dynamic folder = shell.NameSpace(pathOnly);
dynamic folderItem = folder.ParseName(filenameOnly);
if (folderItem != null)
{
dynamic link = folderItem.GetLink;
return "\""+link.Path +"\"" + " " + link.Arguments;
}
return String.Empty; // Not found
}