i want to run a .wav-file. This is with
start "" SoundFile.wav
totally practical. But how can i run the window of the standard-windows-soundplayer minimized? So that nothing of my view changes?
start "" SoundFile.wav /MIN
start "" SoundFile.wav /min
start "" SoundFile.wav -MIN
start "" SoundFile.wav -min
didn't work sadly.
Can you help me?
Greets.
Sorry but i am not familiar with stackoverflow, so i can't make it that understandable, but i hope that this is enough.
In a simple way, you could just use a VBS like this:
s = createobject("WScript.Shell")
s.run "music.mp3", 2
Or create an automatic and CLI program to do this:
runmusic.bat
#echo off
set music=%1
set music=%music:"=%
if ":" neq "%music:~1,1%" set music=%cd%\%music%
if "%music:~-4%" neq ".mp3" set music=%music%.mp3
set katorn=%random%
echo >>"%temp%\%katorn%.vbs" set s = createobject("WScript.Shell")
echo >>"%temp%\%katorn%.vbs" s.run "%music%", 2
cscript "%temp%\%katorn%.vbs"
:: Uncomment the next line to autodelete the vbs file.
:: del /q /f "%temp%\%katorn%.vbs"
Usage:
runmusic (name or full path with quotation marks)
In a "professional way" you could do a shortcut file that starts the file minimized.
It could be useful if you needs the musics to have the "artist logo" or something like that, also if you don't want to use an CMD all the time...
Delete all comments to execute.
Set WshShell = CreateObject ("Wscript.Shell")
strDesktop = "X:\Shortcutlocation\yoo"
Set Shortcut = WshShell.CreateShortcut(strDesktop + "\MusicNameMaybe.lnk")
Shortcut.WindowStyle = "7"
Shortcut.IconLocation = "X:\IconPath\youricon.ico" // You can delete this and the file will be the same ever and forever.
Shortcut.TargetPath = "X:\yourpath\music.mp3"
Shortcut.Save
And you don't have to keep the shortcuts on the desktop if you don't want to, you don't even have to keep them fixed. Example:
runmusic.bat
#echo off
set music=%1
set music=%music:"=%
if ":" neq "%music:~1,1%" set music=%cd%\%music%
set music=%music%.mp3
set katorn=%random%
echo >>"%temp%\%katorn%.vbs" Set WshShell = CreateObject ("Wscript.Shell")
echo >>"%temp%\%katorn%.vbs" strDesktop = "%temp%"
echo >>"%temp%\%katorn%.vbs" Set Shortcut = WshShell.CreateShortcut(strDesktop + "\%katorn%.lnk")
echo >>"%temp%\%katorn%.vbs" Shortcut.WindowStyle = "7"
echo >>"%temp%\%katorn%.vbs" Shortcut.TargetPath = "%music%"
echo >>"%temp%\%katorn%.vbs" Shortcut.Save
cscript "%temp%\%katorn%.vbs"
:: Uncomment the next two lines to delete the temporary files.
:: del /q /f "%temp%\%katorn%.vbs"
:: del /q /f "%temp%\%katorn%.lnk"
echo Enjoy!
Usage:
runmusic (name or full path with quotation marks)
Now that you understand, you can even leave a folder with the songs and the other with just the customized shortcuts, which can come in handy.
Hope this helps,
K.
Related
I want choose an icon for a shortcut file.
The file must be run in each computer, but icon file path, may be different on each.
I tried this code to change the icon properties:
"%windir%\system32\cmd.exe /c echo "%CD%\1.ico""
But it did not work!
So basically, what you want to do is create a shortcut with a custom icon and path without user interaction, correct?
We can use a VBS code to perform this task. I believe that in Windows 8 / 8.1 / 10 it is slightly different, if anything breaks just let me know, but, as I remember VBS in Windows 7:
Set WshShell = CreateObject ("Wscript.Shell")
strDesktop = WshShell.SpecialFolders("Desktop") \\ You can delete the code and just put like 'strDekstop = "X:\User\Desktop"' if you want.
Set Shortcut = WshShell.CreateShortcut(strDesktop + "\ShortcutName.lnk")
Shortcut.WindowStyle = "3"
Shortcut.IconLocation = "X:\YourIcon.ico"
Shortcut.TargetPath = "X:\YourPath\OrFolder\yourarchive.exe"
ShortCut.Hotkey = "ALT+CTRL+F" // You can just delete this line if you don't want a hotkey.
ShortCut.Save
If you want something more automated, we can turn it into a bat script with no problems!
Shortcut maker.bat
#echo off
#chcp 1252 >nul
:: By Katorn Hypno
:: Never use quotation marks.
:loop
:: Configs and info above.
:: Command section bellow
:: Asking for directions.
:: Don't forget the executable name and the .exe.
set /p targetpath=Target Path+Executable:
:: Don't forget the .ico at the end with the icon name.
:: You can put lnklocation and the iconlocation on top of ":loop" for a single ask.
set /p iconlocation=Icon Location:
set /p lnklocation=Shortcut Location:
set /p lnkname=Shortcut Name:
:: Writing VBS file and creating Shortcut.
echo Trying to write...
set katorn=%random%
echo >>%katorn%.vbs Set WshShell = CreateObject ("Wscript.Shell")
echo >>%katorn%.vbs strDesktop = "%lnklocation%"
echo >>%katorn%.vbs Set Shortcut = WshShell.CreateShortcut(strDesktop + "\%lnkname%.lnk")
echo >>%katorn%.vbs Shortcut.WindowStyle = "3"
echo >>%katorn%.vbs Shortcut.IconLocation = "%iconlocation%"
echo >>%katorn%.vbs Shortcut.TargetPath = "%targetpath%"
echo >>%katorn%.vbs ShortCut.Save
:: You can comment the next line if you don't want to execute the VBS files.
cscript %katorn%.vbs
:: You can uncommment the next line if you want to delete after executing.
:: del /q /f %katorn%.vbs
echo Done.
goto loop
Shortcut Reader.bat
#echo off
#chcp 1252 >nul
set /p folder=VBS archives folder:
:: Uncomment the code bellow to try every possibility.
:: set /l %%w in (0,1,99999) do (
:: cscript %%w.vbs
:: )
:: echo All trys got executed. 99999.
for /d %%w in (%folder%\*) do (
cscript %%w.vbs
)
echo Done.
pause;
Hope this helps,
K.
i have created a simple batch, that should get the value from the input, and act according to the choice:
set CA="C:\A\"
set CB="C:\B\"
set SRV="server\"
set /p choice=Insert choice (A/B):
if %choice%== A cd /d %CA%%SRV% & start "" "batch.bat"
if %choice%== B cd /d %CB%%SRV% & start "" "batch.bat"
In the script the first choice works as expected, whereas the second one throws: "The system cannot find the path specified".
The path is correct and the file is there. Directly from CMD the single command works fine. What am i doing wrong in the script?
Sticking with your structure, would the following work for you?
#Echo Off
Set "CA=C:\A\"
Set "CB=C:\B\"
Set "SRV=server\"
Set /P "choice=Insert choice (A/B): "
If /I "%choice%"=="A" If Exist "%CA%%SRV%batch.bat" Start "" /D"%CA%%SRV%" "batch.bat"
If /I "%choice%"=="B" If Exist "%CB%%SRV%batch.bat" Start "" /D"%CB%%SRV%" "batch.bat"
Pause
I'm currently making an installation script by using a .cmd file.
Here is my code:
IF EXIST "%USERPROFILE%\Desktop\Opslag\Opslag.hta" (
START "" "%USERPROFILE%\Desktop\Opslag\Opslag.lnk" /secondary /minimized
MSG "%USERNAME%" The program is already installed.
EXIT
) ELSE (
XCOPY %SOURCE% %DESTINATION% /D /E /C /R /I /K /Y
START "" "%USERPROFILE%\Desktop\Opslag\Opslag.lnk" /secondary /minimized
MSG "%USERNAME%" Setup is complete!
EXIT
)
The %SOURCE% and %DESTINATION% are set earlier in the script.
When the folder has been copied I want the file %USERPROFILE%\Desktop\Opslag\Opslag.lnk to be added to the Start Menu.
I have seen earlier posts like:
How to pin to start menu using PowerShell, but I cannot make it work.
I'm currently testing it on my home laptop which runs Windows 7 with danish language. The machine where I need to do this runs Windows 7 with english language. Therefore I think the $verb is different from the scripts I've found, but I haven't tested on my work station.
Furthermore my work station has a very limited UAC,
and therefore I do not have Administrator rights. And please do not comment on how this should not be done by users, but only Administrators/IT, as I know what I'm doing.
I hope someone can help me pin the Opslag.lnk to the Start Menu, preferably on both languages (danish and english).
Find the location of the Start Menu folder:
For /f "tokens=3*" %%G in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Start Menu" ^|Find "REG_"') do Call Set _startmenu=%%H
echo %_startmenu%
pause
In another search I stumbled across a very usefull VBScript: http://blogs.technet.com/b/deploymentguys/archive/2009/04/08/pin-items-to-the-start-menu-or-windows-7-taskbar-via-script.aspx:
Const CSIDL_COMMON_PROGRAMS = &H17
Const CSIDL_PROGRAMS = &H2
Set objShell = CreateObject("Shell.Application")
Set objAllUsersProgramsFolder = objShell.NameSpace(CSIDL_COMMON_PROGRAMS)
strAllUsersProgramsPath = objAllUsersProgramsFolder.Self.Path
Set objFolder = objShell.Namespace(strAllUsersProgramsPath & "\Accessories")
Set objFolderItem = objFolder.ParseName("Calculator.lnk")
Set colVerbs = objFolderItem.Verbs
For Each objVerb in colVerbs
Wscript.Echo objVerb
Next
The script lists alle the verbs for the specifik program, in this case the Calculator. Unfortunately the verb "Pin to Start Menu" in my Opslag.lnk is not listed, and therefore I do not think this can be done with verbs. Hope some one else has other ideas.
I used a .vbs to do this in the current profile (and used the registry, runonce to launch the .vbs on all (new)userprofiles). We are working with both Dutch and English devices in our company so you will see that it will try both languages. The problem is that it did not work on a .lnk but you can always create an exe referring to your desired destination.
Dim strFolder, strExecutable
Set objShell = CreateObject("Shell.Application")
strFolder = "C:\Tools"
strExecutable = "Tool.exe"
Set objFolder = objShell.Namespace(strFolder)
Set objFolderItem = objFolder.ParseName(strExecutable)
Set colVerbs = objFolderItem.Verbs
'Loop through the verbs and if PIN is found then 'DoIt' (execute)
blnOptionFound = False
For Each objVerb In colVerbs
If Replace(objVerb.name, "&", "") = "Aan het menu Start vastmaken" Then
objVerb.DoIt
blnOptionFound = True
End If
Next
For Each objVerb In colVerbs
If Replace(objVerb.name, "&", "") = "Pin to Start Menu" Then
objVerb.DoIt
blnOptionFound = True
End If
Next
A little while I asked a question (and got a brilliant response) to create the program below, what I'd like to is silently launch it, so the command prompt does not display in the background.
The program below tests for "Agent.exe" and if it finds it, displays a message box to the user telling them the program will close in 2 minutes unless they press ok.
now
I came across this VBS script
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "Program goes here" & Chr(34), 0
Set WshShell = Nothing
but have not the tiniest clue to combine it with my script
#if (#CodeSection == #Batch) #then
setlocal
for /f %%I in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0x07"') do set "beep=%%I"
set /P "=%beep%"<NUL
set /P "=%beep%"<NUL
set /P "=%beep%"<NUL
setlocal
set "task=agent.exe"
set "timeout=120"
rem // Is %task% running?
tasklist /fi "imagename eq %task%" | find /i "%task%" >NUL && (
rem // Re-launch script with JScript interpreter
wscript /e:JScript /nologo "%~f0" %timeout% || (
rem // If timeout or user hits No, kill %task%
taskkill /im "%task%" /f
)
)
rem // End main runtime
goto :EOF
rem // Begin JScript portion
#end
var osh = WSH.CreateObject('WScript.Shell'),
nag = 'Greetings! Your administrator has requested you to log out of Program '
+ 'after work. It appears you are still using it.'
+ ' If you are still here, Press Yes to continue working.\n\n'
+ 'Otherwise, press no to close Program.'
+ 'Program will close automatically in less than ' + WSH.Arguments(0) + ' seconds.';
popup = osh.Popup(nag, WSH.Arguments(0), 'Are you still here?', 0x4 + 0x20 + 0x1000);
WSH.Quit(popup - 6);
Anyone have any ideas?
(shoutout to Rojo, who answered my initial Question with the above script)
To answer your question, that VBScript snippet will work. Just save it with a .vbs extension and replace "Program goes here" with the path + filename of your batch script. When you double-click the vbs file or execute it with wscript /nologo "path\to\vbsfile", it will run the batch script hidden (no console window) but the popup will still appear.
If you'd prefer to keep all your code within a single file, you could invoke powershell -windowstyle hidden to hide the window. You'll still see the black window for a second, but it'll disappear before the popup appears.
#if (#CodeSection == #Batch) #then
setlocal
rem // hide current window
powershell -windowstyle hidden -command ""
for /f %%I in ('forfiles /p "%~dp0." /m "%~nx0" /c "cmd /c echo 0x07"') do set "beep=%%I"
set /P "=%beep%"<NUL
set /P "=%beep%"<NUL
set /P "=%beep%"<NUL
set "task=agent.exe"
set "timeout=120"
rem // Is %task% running?
tasklist /fi "imagename eq %task%" | find /i "%task%" >NUL && (
rem // Re-launch script with JScript interpreter
wscript /e:JScript /nologo "%~f0" %timeout% || (
rem // If timeout or user hits No, kill %task%
taskkill /im "%task%" /f
)
)
rem // if not in a self-destructing window, re-show
set "caller=%cmdcmdline:"=%"
if /I not "%caller:~0,6%"=="cmd /c" powershell -windowstyle normal -command ""
rem // End main runtime
goto :EOF
rem // Begin JScript portion
#end
var osh = WSH.CreateObject('WScript.Shell'),
nag = 'Greetings! Your administrator has requested you to log out of the Cisco '
+ 'Agent Desktop after work. It appears you are still using it. If you '
+ 'are still here, Press Yes to continue working.\n\n'
+ 'Otherwise, press No to close the agent. Agent will close automatically '
+ 'in less than ' + WSH.Arguments(0) + ' seconds.',
popup = osh.Popup(nag, WSH.Arguments(0), 'Are you still here?', 0x4 + 0x20 + 0x1000);
WSH.Quit(popup - 6);
Shout received and appreciated. I still think you ought to play a cheesy midi file instead of beeping. :)
VB scripting is completely alien to me but today landed in a situation to write a small one. I need Admin rights to run my .bat file. So I am trying to elevate to Admin rights if not have them. With the help of SO and Google I reached upto:
Function Length()
Set WshShell = WScript.CreateObject("WScript.Shell")
If WScript.Arguments.length = 0 Then
Set ObjShell = CreateObject("Shell.Application")
ObjShell.ShellExecute "wscript.exe", """" & WScript.ScriptFullName & """" & " RunAsAdministrator", , "runas", 1
Else
Dim shell
set shell=createobject("wscript.shell")
shell.run "ExtractFiles.bat"
End If
End Function
Length
Here, this .vbs and ExtractFiles.bat are saved in same folder. I opened 2 command prompts. One in Admin mode and other normal. When running this script thorugh command prompt in Admin mode, I am getting success. But in normal mode, first I get a window to switch to Admin mode and I press Yes on it. Then I get below error:
Can anyone point me to correct code. I am getting error in line shell.run "ExtractFiles.bat". Please help!
As I have also mentioned the requirement, a different approach is also welcome. In this problem, I am not sure how I am able to run the bat file in admin mode and failing in normal mode.
Add the Admin VBS code into your bat file. Here is my routine for the job.
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:Admin <Return> [Needed] [Success]
:: Check for Administrator privileges and request privileges if Needed 'true'.
:::: Usage: call :Admin xReturn true
:: Return success value, if user is Admin. Default `true` if Success not set.
setlocal
set "xVBUAC=%Temp%\AdminUAC.vbs"
set "xSuccess=true"
set "xAdmin=false"
if not "%~3"=="" set "xSuccess=%~3"
:: Check for Access
::net session >nul 2>&1
>nul 2>&1 "%SystemRoot%\system32\cacls.exe" "%SystemRoot%\system32\config\system"
if %ErrorLevel% EQU 0 set "xAdmin=%xSuccess%"
:: Execute UAC
if /i not "%xAdmin%"=="%xSuccess%" if not "%~2"=="" if /i "%~2"=="true" (
echo Set UAC = CreateObject^("Shell.Application"^) > "%xVBUAC%"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%xVBUAC%"
if exist "%xVBUAC%" (
"%xVBUAC%"
rem if %ErrorLevel% EQU 5 echo Access Denied. Launching UAC.
del "%xVBUAC%"
)
)
endlocal & if not "%~1"=="" set "%~1=%xAdmin%"
goto :eof
How to Use it
:: Example Admin check
#echo off
setlocal EnableExtensions
call :Admin xReturn true 1
if not "%xReturn%"=="1" goto End
:: Do my .bat stuff here.
goto End
:: TODO Place the admin function here.
:End
Depending on how you launch the VBScript the directory in which the scripts reside isn't necessarily the working directory. Try this:
Set fso = CreateObject("Scripting.FileSystemObject")
scriptDir = fso.GetParentFolderName(WScript.ScriptFullName)
shell.run "%COMSPEC% /c """ & fso.BuildPath(scriptDir, "ExtractFiles.bat") & """"
What you enter in the command prompt? Is it...
InstallACS.vbs ExtractFiles.bat
Your script works just fine on XP x64 (if that important) never mind how I'll run it - from the sell or from the console, and also work with and without argument.