i am trying to run a command like TASKKILL /F /IM notepad.exe
var process = Ti.Process.createProcess({args: ['TASKKILL /F /IM notepad.exe']});
process.launch();
or
Ti.Process.launch('TASKKILL /F /IM skype.exe');
the debugger doesn't say much, just Error launching 'TASKKILL /F /IM notepad.exe'
documentation
any ideas?
In order to create process I use this syntax (coffeeScript) :
customProcess = Ti.Process.createProcess([
arg1
arg2
arg3
])
customProcess.launch()
Here is an example of how I use Ti.Process : executing the wkhtmltopdf binary in order to create a pdf from HTML/CSS. So I use the following :
pdfProcess = Ti.Process.createProcess([
Ti.API.application.getResourcesPath() + '/wkhtmltopdf/builds/win32/wkhtmltopdf/bin/wkhtmltopdf.exe'
'--margin-bottom'
30
'--margin-top'
40
sourcePath
'--header-html'
headerPath
'--footer-html'
footerPath
destinationPath
])
pdfProcess.launch()
I haven't tried but maybe the following will work :
exitProcess = Ti.Process.createProcess([
'TASKKILL'
'/F'
'/IM'
'notepad.exe'
])
exitProcess.launch()
I think you'll have to split each argument of your process in a item of a list.
Related
Actually I need to delete any task that contain some particular string.
I use schtasks /query /v /fo list to list all tasks and schtasks /delete /tn XX /fto remove a specific task.
Right now after I listed all tasks, I have to use Ctrl + F to find the string and copy paste manually.
Is it possible to show only task name that contain specific string in Task To Run? or even I can delete all the related task in one shot.
Thanks.
Set TS = CreateObject("Schedule.Service")
TS.Connect("DESKTOP-UCDGI39")
Set rootFolder = TS.GetFolder("\")
Set tasks = rootFolder.GetTasks(0)
If tasks.Count = 0 Then
Wscript.Echo "No tasks are registered."
Else
WScript.Echo "Number of tasks registered: " & tasks.Count
For Each Task In Tasks
A=Task.Name
A = A & " " & Task.NextRunTime
wscript.echo A
Next
End If
For more info and sample code https://learn.microsoft.com/en-us/windows/win32/taskschd/displaying-task-names-and-state--scripting-.
In a Windows 10 environment, if I don't have access to the task scheduler that is executing my bat file, can I (from within the batch file) know the name of the task that has launched the batch file? Is there a variable that gets set with the task scheduler task name that I can use?
The obvious solution would be to add a task name parameter when calling the action in the task scheduler, but what if I have no access to the task scheduler?
I hope this solution works for you.
Below you can find:
a .BAT file and a .VBS that contains the function.
as for the .BAT:
#ECHO OFF
SET DT=%DATE% %TIME%
SET DATETIME=%DT:~0,19%
FOR /F "usebackq tokens=*" %%r in (`CSCRIPT "C:\<your_folder>\current_task_name.vbs" "%~dpnx0" "%DATETIME%"`) DO SET current_task_name=%%r
ECHO script was executed by: %current_task_name%
PAUSE
as for the VBS named: current_task_name.vbs
getMyTask WScript.Arguments.Item(0), WScript.Arguments.Item(1)
Function getMyTask(Cmd, StartDateTime)
' ----------------------------------------------------------------------
' Script to list all Scheduled tasks and their available properties
' Written for TaskSchedule 2.0
' ----------------------------------------------------------------------
Dim objTaskService, objTaskFolder, colTasks
Dim objTask
' Create the TaskobjTaskService object and connect
Set objTaskService = CreateObject("Schedule.Service")
Call objTaskService.Connect
' Get the task folder that contains the tasks.
Set objTaskFolder = objTaskService.GetFolder("\")
' Get all of the tasks (Enumeration of 0 Shows all including Hidden. 1 will not show hidden)
Set colTasks = objTaskFolder.GetTasks(0)
If colTasks.Count = 0 Then
wscript.echo "No registered tasks."
Else
For Each objTask In colTasks
With objTask
'check if the time of execution is in the same range of the current task (~ 2 secs. after)
If DateDiff("s", .LastRunTime, StartDateTime) <= 2 Then
Set objTaskDefinition = .Definition
With objTaskDefinition
Set colActions = objTaskDefinition.Actions
For Each objTaskAction In colActions
With objTaskAction
Select Case .Type
Case 0 '= Execute / Command Line Operation
'If .Path of TaskAction object is equal to the batch file name provided
'it returns its task name back
If .Path = Cmd Then
wscript.echo objTask.Name
wscript.quit
End If
End Select
End With
Next
End With
End If
End With
Next
End If
End Function
regards,
jtandrea
So I map a drive to T \server01\tfolder
I need a script which does the following
If T is mapped to \server01\tfolder then map it to server02\tolder. But if drive is mapped to \server02\tfolder then map it to \server01\tfolder
I am using an else switch but already but can't for the life of me work out how I get it to confirm which its being mapped to already and then map it to the alternate.
Any ideas?
for /f "tokens=2" %%a in ('net use t: ^|find "\\"') do set "current=%%a"
if "%current%" == "\\server01\tfolder" (
set "new=\\server02\tfolder"
) else (
set "new=\\server01\tfolder"
)
echo switching from %current% to %new%
I want to replace OLD with %NEW% in test.txt by using a batch file:
#echo off
set /p NEW=""
set InputFile=test.txt
find OLD
replace %NEW%
my test.txt contains various characters like ~ : ; _ .which I attribute to various solutions clapping out.
I have attempted to use BatchSubstitude.bat to achieve this but it does not "find" OLD and does not replace any text.
I have also attempted to use fart.exe but I receieve an error when trying to perform this:
find_string="OLD"
replace_string="test"
actual find_length=3
actual replace_length=4
processing \filepath\,test.txt
skipping binary file: \filepath\test.txt
The documentation for this is sparse and nothing I could google furiously would provide a solution.
The reason I am using batch for the moment is that I perform various windows CE actions such as cecopy, pdel and rapistart for windows CE deployment over activesync and batch seems to be the easiest way to to get the result that I am after - and I'm a total noob at batch.
Does anyone know how this can be achieved with batch and perhaps explain how the various functions work to achieve this?
Cheers!
Try this:
#set #a=0 /*
#echo off
set /p NEW=""
set InputFile=test.txt
cscript //nologo //E:JScript "%~F0" "%NEW%" < "%InputFile%" > output.tmp
move /Y output.tmp "%InputFile%"
#goto :EOF */
WScript.Stdout.Write(WScript.Stdin.ReadAll().replace(/OLD/g,WScript.Arguments(0)));
Do not download anything from sourceforge so better to skip fart-it.
The method in the dostips is not so robust when special characters are used (&<>|^) as it is pointed there.Here's a simple batch/jscript that will replace a content in a file (you can change the hardcoded things like file location):
0</* :
#echo off
set "file=c:\test.txt"
set "find=OLD"
set /p "replace=NEW: "
cscript /nologo /E:jscript "%~f0" %file% %find% %replace%
echo ==replaced==
exit /b */0;
var FSOObj = new ActiveXObject("Scripting.FileSystemObject");
var ARGS = WScript.Arguments;
if (ARGS.Length < 3 ) {
WScript.Echo("Wrong arguments");
WScript.Quit(1);
}
var filename=ARGS.Item(0);
var find=ARGS.Item(1);
var replace=ARGS.Item(2);
var readStream=FSOObj.OpenTextFile(filename, 1);
var content=readStream.ReadAll();
readStream.Close();
function replaceAll(find, replace, str) {
return str.replace(new RegExp(find, 'g'), replace);
}
var newConten=replaceAll(find,replace,content);
var writeStream=FSOObj.OpenTextFile(filename, 2);
writeStream.WriteLine(newConten);
writeStream.Close();
Check also this more advanced tools
FindRepl
JRepl
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.