I want to install license for my PC. However, I can't add parameter for the method.
My code:
#echo off
for /r "%SystemRoot%\system32\spp\tokens" %%f in (*.xrm-ms) DO (
wmic path SoftwareLicensingService WHERE (Version is not null) call InstallLicense License='<%%f'
)
pause
Like I want to read all text in the files of "tokens" directory and send it to License parameter.
Here is VB code. I can do it in VB but not in .bat file (Batch)
Dim files As String() = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.System) & "\spp\tokens", "*.xrm-ms", SearchOption.AllDirectories)
wmic = New ManagementObjectSearcher("SELECT Version FROM SoftwareLicensingService").Get()
For Each i As String In files
For Each wmi As ManagementObject In wmic
wmi.InvokeMethod("InstallLicense", {File.ReadAllText(i)})
Next
Next
Thanks all. Sorry for my bad English because I'm Chinese :(
Related
I have a .bat file that I am using to run a .Msi in silent mode. Now I wanna run that batch script command from vb.net. I tried using process.start(). Using process.start() opens the files, But the issue is the batch script is not executed and .Msi is not installed.I tried executing the same command directly from cmd and it worked.
Now, Can someone help me how I can execute that command form vb.net.(Can someone help me Write that command to the cmd window after starting the cmd process from vb.net). I tried using standardinput.Writeline(), It is opening the .txt files, But it is not working for executing the commands for installing the .Msi file.
Dim command As String="# echo off msiexec /i
""C:\Users\tparvathaneni\Documents\Visual Studio 2015\Projects\SetupProject1\SetupProject1\bin\Debug\SetupProject1.msi"" /qn REBOOT=ReallySuppress echo pause >NUL shutdown.exe /r/t 000"
Dim proc As New ProcessStartInfo
proc.FileName = "cmd.exe"
proc.RedirectStandardInput = True
proc.RedirectStandardOutput = True
proc.CreateNoWindow = True
proc.UseShellExecute = False
Dim pr As New Process
pr.StartInfo = proc
pr.Start()
pr.BeginOutputReadLine()
pr.StandardInput.WriteLine(command)
Throwing this into your VBS will launch the batch script without a window or tray icon. This may be an easier way than trying to send commands to your batch window.
Set WshShell = CreateObject("WScript.Shell" )
WshShell.Run chr(34) & "C:\Temp\YourFile.bat" & Chr(34), 0
I have RAR SFX with some programs. Depending on some conditions (command line parameter is something i can do), SFX should either extract to TEMP folder, or the current folder.
It's basicaly new version of the software.
If downloaded from the web, extraction should go into temp folder, and then installation searches for the map where SW is located.
If downloaded from inside the program, then i know the program location relative to download path and extraction should go into current folder...
Any way I can achieve this using RAR SFX?
TNX.
Inside your program you can skip SFX header of file and extract it as regular RAR file in folder yo want.
It need few lints of code or embding Winrar or 7zip liraries.
This batch code show you how we can create an SFX (SelF-eXtracting) protected with a password and with a custom icon too if you want to add them of course
#echo off
Set SFX_Name=TestSFX.exe
Set SfxOptions=SfxOptions.txt
Set AddFile=MyBatchFile.bat
Set Icon=HackooIcon.ico
Set Winrar="%ProgramFiles%\WinRAR\WinRar.exe"
Set ExtractedPath=%tmp%\hackoo
Set Setup=%ExtractedPath%\MyBatchFile.bat
Set Password=hackoo123
(
echo ;The comment below contains SFX script commands
echo Path="%ExtractedPath%"
echo Silent=1
echo OverWrite=1
echo Setup="%Setup%"
)> "%SfxOptions%"
%Winrar% a -c -cfg- -ep1 -idq -m5 -mdg -r -s -sfx -y -iicon"%Icon%" -hp"%Password%" "-z%SfxOptions%" "%SFX_Name%" "%AddFile%"
if errorlevel 1 goto Failure
::del "%~dp0SfxOptions.txt"
goto :EOF
:Failure
::del "%~dp0SfxOptions.txt"
echo.
echo Error on creation of "%~dp0%SFX_Name%"
echo.
pause
For others switchs and commands you can execute this batch to open the help file of Winrar :
#echo off
Set WinrarHelp=%ProgramFiles%\WinRAR\WinRAR.chm
Start "" "%WinrarHelp%"
I need a way of downloading a program through either visual basic or cmd. I have tried these, but the file after it's downloaded is only about 600 bytes and doesn't work. I own this website and have ftp access, if I download it through ftp it's fine. I'm using Visual Studio 2013 by the way. These are the methods I've tried:
CMD through VB:
Dim MyCmd, Ws, Ret
Ws = CreateObject("wscript.Shell")
MyCmd = "cmd /c Powershell.exe -ExecutionPolicy bypass -noprofile -WindowStyle Hidden (New-Object System.Net.WebClient).DownloadFile('http://minecraftmapmakerstool.16mb.com/downloads/The_Map_Makers_Tool.exe','C:\Users\user\Desktop\The_Map_Makers_Tool.exe'); Start-Process C:\Users\user\Desktop\The_Map_Makers_Tool.exe;"
Ret = Ws.run(MyCmd, 0, True)
VB:
My.Computer.Network.DownloadFile("http://minecraftmapmakerstool.16mb.com/downloads/The_Map_Makers_Tool.exe", "C:\Users\user\Desktop\The_Map_Makers_Tool.exe")
Thanks in advance :)
I think there is no built in tool in Windows that would do that for you. But there are plenty free programs on the web, that you can install and then call from your batch script. Here is one of them: CURL
Here is a basic example of how to use it (using your link)
#echo Off
Title
Pause
CD C:\Users\Jah\desktop
curl http://www.jah.com/ofac/downloads/t11sdn.pdf > download.pdf
This would download and save the file from the URL you have provided to download.pdf
Another possible alternative would be WGET.
I'm new to WIMC so probably there will be simple answer to my question.
If I will open CMD and run this command:
wmic /OUTPUT:C:\LogServices.txt service where "not PathName like '%Windows%'" get DisplayName,Name,PathName,State,StartMode
this will generate file with all services not in windows folder.
If I will save above command in bat file and run this will generate list all services somehow ignoring WHERE statement. Running this as Administrator not changing anything.
In a batch script you have to double pump the % signs so they'll be treated as literal percent signs. Change your command to this and it'll work:
wmic /OUTPUT:C:\LogServices.txt service where "not PathName like '%%Windows%%'" get DisplayName,Name,PathName,State,StartMode
I am shelling in the a few push d statements based on a list of users from the active directory. 2 for example are
java.exe -version
and
dir /s
The search actually seems to search the actual computer and output the files from their directory. However, the java.exe only outputs the actual output from the computer that it is being ran on.
Is this even possible to run a remote exe from the pushd statement? Any thoughts would be great.
Here is the code as of right now in a simplified version. Let me know if anyone would like more.
Dim sCommand as String = "pushd \\***\C$ && java.exe -version 2>>C:\Testfile.txt"
Dim sCommand2 as String = "pushd \\***\C$ && dir /s blah.blah>>C:\Testfile.txt"
For each SelectedItem in Listbx.SelectedItems
Dim ReplaceCommand as String = sCommand.Replace("***", SelectedItem)
Shell("cmd.exe /c" & ReplaceCommand, True)
Dim ReplaceCommand as String = sCommand2.Replace("***", SelectedItem)
Shell("cmd.exe /c" & ReplaceCommand2, True, -1)
Next
To me, you'll need to find on the remote computer first the location of the JAVA executable. Your commands you're executing on the shell will search your local defined paths, not the remote paths.
Consider this.
first execution is local > running java 1.6.0.23
then I pushd to another computer. I re-execute the same command.
Since i'm not in the remote directory containing the java.exe file, it'll process my path to find it. >same version is returned
I then change to the remote's Java container and re-execute the statement.
This time it's finding the remote Java.exe and processes the command.