הערה
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות להיכנס או לשנות מדריכי כתובות.
הגישה לדף זה מחייבת הרשאה. באפשרותך לנסות לשנות מדריכי כתובות.
Question
Thursday, November 28, 2013 8:16 AM
I am trying to create a scheduled task using schtask from command line. The problem is the same issue the space problem in the app path. I am using Application.StartupPath and exe name. So in the application.startuppath there is a space and I can't figure out anything to fix it.
Dim pr As New Process
pr.StartInfo.FileName = "schtasks.exe"
pr.StartInfo.Arguments = "/Create /SC HOURLY /TN ""My Test App"" /TR """ & Application.StartupPath & "\Checks.exe"" /RL HIGHEST"
pr.Start()
All replies (31)
Wednesday, December 4, 2013 8:27 AM ✅Answered | 1 vote
Hi,
using Win7 32 bit,TaskScheduler V1.0, VB.NET 2010 this is working like a charme on my side:
Dim pr As New System.Diagnostics.Process
pr.StartInfo.FileName = "schtasks.exe"
pr.StartInfo.Arguments = "/Create /SC HOURLY /TN ""My Test App"" /TR ""'" & Application.StartupPath & "\Checks.exe" & "'"""
pr.Start()
So the little tricky part here is that you need to add a single quot also before and after the filename which contains a space in it.
Hannes
If you have got questions about this, just ask.
In a perfect world,
users would never enter data in the wrong form,
files they choose to open would always exist
and code would never have bugs.
Wednesday, December 4, 2013 1:07 PM ✅Answered
I have it working completely on my computer. here is a screenshot for task scheduler:
Below is my code:
Try Dim pr As New Process Dim a As Integer pr = Process.Start("C:\Windows\System32\cmd.exe") System.Threading.Thread.Sleep(2000) a = pr.Id AppActivate(a) My.Computer.Keyboard.SendKeys("schtasks.exe", True) My.Computer.Keyboard.SendKeys("/Create /SC WEEKLY /TN MyTestApp /TR " + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) + " /RL HIGHEST", True) My.Computer.Keyboard.SendKeys("{Enter}", True) ' pr.StartInfo.FileName = "schtasks.exe" ' pr.StartInfo.Arguments = "/Create /SC HOURLY /TN My Test App /TR" + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) '+ "/RL HIGHEST" Catch ex As Exception MsgBox(ex.ToString()) End Try
It was the spaces and improper characters (I already stated the quotes above in a previous post).
I tried the exact code on my system, and like I always said it DOES create the task. But the problem is in the image below:-
Now if you simply right click the task and click RUN. Firefox won't start because the path of the program is like in the image above. THAT is the same problem I have.
I get close but everytime I Input program files the x86 version it trims out the ( and ) characters:
Try Dim pr As New Process Dim a As Integer pr = Process.Start("C:\Windows\System32\cmd.exe") System.Threading.Thread.Sleep(2000) a = pr.Id AppActivate(a) My.Computer.Keyboard.SendKeys("schtasks.exe /Create /SC WEEKLY /TN MyTestApp23 /TR " + Chr(34) + Chr(39) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(39) + Chr(34), True) 'My.Computer.Keyboard.SendKeys("), True) My.Computer.Keyboard.SendKeys("{Enter}", True) ' pr.StartInfo.FileName = "schtasks.exe" ' pr.StartInfo.Arguments = "/Create /SC HOURLY /TN My Test App /TR" + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) '+ "/RL HIGHEST" Catch ex As Exception MsgBox(ex.ToString()) End Try
Task scheduler is making me mad because it truncates the ( and ) characters if I send them through the command line with visual studio.
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
If I use a normal path string such as "c:\program files\dvd maker\dvd maker.exe" the above works. However, it does not if you use ( and ) in the path string. Microsoft screwed up somewhere because task scheduler does not accept weird paths unless I forgot a setting in visual studio somewhere. If i do program files (x86) from the command line manually though it works. Edit: heres a picture:
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
This is exactly what I told. I am not able to give the path from Visual Studio. I need this definitely to work.
I changed my code to directly send the program files path to task scheduler and it fully works now taking every weird path I have sent it so far:
Dim pr As New System.Diagnostics.Process
pr.StartInfo.FileName = "schtasks.exe"
pr.StartInfo.Arguments = "/Create /SC WEEKLY /TN MyTestApp23 /TR " + Chr(34) + Chr(39) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(39) + Chr(34)
pr.Start()
You should be able to change some command line options too but if you are unsure about something ask. I have also placed my program in firefoxs program files folder to test for some administrative/deployment weirdness to see if my code will still start firefox and it does:
Dim pr As New System.Diagnostics.Process
pr.StartInfo.FileName = "schtasks.exe"
pr.StartInfo.Arguments = "/Create /SC WEEKLY /TN MyTestApp23 /TR " + Chr(34) + Chr(39) + Application.StartupPath + "\firefox.exe" + Chr(39) + Chr(34)
pr.Start()
Note: in the above statement replace firefox with checks.exe. I just wanted to test to make sure if you deployed under program files (x86) it would work.
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
Thursday, November 28, 2013 5:32 PM
I haven't done it but from this link Schtasks the following parameters are for doing that with a password if necessary. The link has many more examples. I replaced the quotes with ChrW(34) since it is easier in order to display quotes in a string than having to use """" or whatever.
Option Strict On
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Text = Application.StartupPath
Dim test As String = "/create /tn " & ChrW(34) & "My App" & ChrW(34) & " /tr " & Application.StartupPath & "\My.Exe" & " /sc once /st 00:00:00 /sd 01/01/2002 /ru Admin23 /rp p@ssworD1"
Label1.Text = test
End Sub
End Class
Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.
Saturday, November 30, 2013 7:29 AM
I haven't done it but from this link Schtasks the following parameters are for doing that with a password if necessary. The link has many more examples. I replaced the quotes with ChrW(34) since it is easier in order to display quotes in a string than having to use """" or whatever.
Option Strict On Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Me.Text = Application.StartupPath Dim test As String = "/create /tn " & ChrW(34) & "My App" & ChrW(34) & " /tr " & Application.StartupPath & "\My.Exe" & " /sc once /st 00:00:00 /sd 01/01/2002 /ru Admin23 /rp p@ssworD1" Label1.Text = test End Sub End Class
Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.
Nope it doesn't create any task. I tried to even keep it simple like this.
Dim pr As New Process
pr.StartInfo.FileName = "schtasks.exe"
pr.StartInfo.Arguments = "/create /sc hourly /tn " & ChrW(34) & "My App" & ChrW(34) & " /tr " & Application.StartupPath & "\Checks.exe"
pr.Start()
Saturday, November 30, 2013 7:36 AM
So far what is working is this:-
Dim checkpath As String = "" & Application.StartupPath & "\Checks.exe"""
Dim cmd1 As String = "/Create /SC HOURLY /TN ""ProSec Security Check"" /TR """ & checkpath & " /RL HIGHEST"
Process.Start("SchTasks.exe", cmd1)
But the problem is when Application.StartupPath = "C:\Users\Admin\Documents\Visual Studio 2010\Projects\Tester-Sec\Tester-Sec\bin\Debug"
So as you can see the first space is after the word Visual. So the task created reads it like this. Look at the image below:-
Saturday, November 30, 2013 7:56 AM
I don't see any image and I clicked on your thread twice in case my internet connection was "sloppy" in some fashion and the image was corrupted in my webbrowsers download.
Please check your thread and if the image is there then disregard this post and if not edit your post and delete whatever the old image is and add a new image to it.
And Instead of adding quotes to your string which could be an issue use & ChrW(34) & which adds a single quote to a string instead of using """ or """" or whatever. Perhaps that is an issue too for all I know.
After all I provided that code in the format I did for a reason. Not to have it circumvented.
Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.
Saturday, November 30, 2013 8:13 AM
Also why do you need to create a string to add into another string? And there is a String.Remove Method which allows you to remove text from a string although the information at the link sucks and I think for the money Microsoft has they could actually provide a decent example of it.
Dim Temp as String = "Hello. How are you doing today?"
Temp = Temp.Remove(7, 1)
Either this removes the space after the period in Hello or it removes the H in How as it only removes one Char and I can't remember if the 7 is the space or the H in how. But give that a try and I figure if you create a string, instead of two strings, then you can remove that space you are talking about really easily.
I just tested it and it removes the H rather than the space.
Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.
Saturday, November 30, 2013 8:21 AM
Just edited the last post. You can see the image now.
Saturday, November 30, 2013 8:28 AM
Tried the same with the following code:-
Dim checkpath As String = ChrW(34) & Application.StartupPath & "\Checks.exe" & ChrW(34)
Dim cmd1 As String = "/Create /SC HOURLY /TN " & ChrW(34) & "ProSec Security Check" & ChrW(34) & " /TR " & checkpath & " /RL HIGHEST"
Process.Start("SchTasks.exe", cmd1)
The task gets created as usual. But the path of the program is the problem. Just like in the image in my previous post.
Saturday, November 30, 2013 8:30 AM
Well I would suggest that you use the string.replace function I previously described in a test app to get rid of that space. And when that works then provide that capability in your actual app.
That's how I have to do things to answer questions on here about issues people are having with code. And I suck at programming compared to the other programmers who answer questions and develop programs for a living like Cor Ligthert and Frank somebody and all these other peeps like Acamar and a whole bunch of others like IronRazers and TommyTwoTrains who actually have experience way beyond mine. Reed Kimble, etc, etc. I hate leaving anybody out but I have brain freeze all the time.
Display the results in a richtextbox or label until you have the result you need then put that code in your real app.
Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.
Saturday, November 30, 2013 8:43 AM
Well I would suggest that you use the string.replace function I previously described in a test app to get rid of that space. And when that works then provide that capability in your actual app.
That's how I have to do things to answer questions on here about issues people are having with code. And I suck at programming compared to the other programmers who answer questions and develop programs for a living like Cor Ligthert and Frank somebody and all these other peeps like Acamar and a whole bunch of others like IronRazers and TommyTwoTrains who actually have experience way beyond mine. Reed Kimble, etc, etc. I hate leaving anybody out but I have brain freeze all the time.
Display the results in a richtextbox or label until you have the result you need then put that code in your real app.
Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.
I already tried that. But there is a problem. I will try to explain as briefly as possible.
The code I used:-
Dim checkpath As String = ChrW(34) & Application.StartupPath & "\Checks.exe" & ChrW(34)
checkpath = checkpath.Replace(" ", "")
Dim cmd1 As String = "/Create /SC HOURLY /TN " & ChrW(34) & "ProSec Security Check" & ChrW(34) & " /TR " & checkpath & " /RL HIGHEST"
Process.Start("SchTasks.exe", cmd1)
It does create a schedule task. The problem now is still the path of the app, currently it is:-
"C:\Users\Admin\Documents\VisualStudio2010\Projects\Tester-Sec\Tester-Sec\bin\Debug\Checks.exe"
The space after Visual and Studio have been removed due to string.replace.
But the task will not start because it wont find a folder "VisualStudio2010", the actual folder name is with space "Visual Studio 2010".
In order to clarify that infact this is the actual problem. I went to task scheduler console and manually browsed the Checks.exe application and then the task started running properly.
I need some workaround to infact provide spaces but schtask should not comprehend it as argument and put it in the arguments box.
Saturday, November 30, 2013 9:18 AM | 1 vote
Well of course those Microsoft idiots have a link to Using the Task Scheduler and the idiots code is I figure mostly in C++ so the original link I provided you about Schtasks may not work. At least with the variety of strings I've tried to use with it didn't work as I checked Task Scheduler after trying to add my app with a varitey of strings for an app but none of them worked. Unless I need to reboot my PC when something is added to Task Scheduler, which I have done manually before, for them to show up. But I haven't rebooted my PC to see if my app showed up as a scheduled task.
Microsoft pisses me off with their poor, crappy documentation which mostly contains examples from idiots that, instead of making the example easy to understand for anybody, requires enormous effort to figure out what the F is going on in the examples posted. What a stupid way to support their own Microsoft Developers Network. Dumb idiots. I figure Bill Gates is too above knowing anything about it cause if I owned that company I would be firing people for that kind of junk.
So unless I feel interested in helping you tomorrow (today where I live) perhaps somebody else can assist you as I'm pretty disgusted by this now!
Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.
Saturday, November 30, 2013 6:08 PM
Well I would suggest that you use the string.replace function I previously described in a test app to get rid of that space. And when that works then provide that capability in your actual app.
That's how I have to do things to answer questions on here about issues people are having with code. And I suck at programming compared to the other programmers who answer questions and develop programs for a living like Cor Ligthert and Frank somebody and all these other peeps like Acamar and a whole bunch of others like IronRazers and TommyTwoTrains who actually have experience way beyond mine. Reed Kimble, etc, etc. I hate leaving anybody out but I have brain freeze all the time.
Display the results in a richtextbox or label until you have the result you need then put that code in your real app.
Please BEWARE that I have NO EXPERIENCE and NO EXPERTISE and probably onset of DEMENTIA which may affect my answers! Also, I've been told by an expert, that when you post an image it clutters up the thread and mysteriously, over time, the link to the image will somehow become "unstable" or something to that effect. :) I can only surmise that is due to Global Warming of the threads.
I already tried that. But there is a problem. I will try to explain as briefly as possible.
The code I used:-
Dim checkpath As String = ChrW(34) & Application.StartupPath & "\Checks.exe" & ChrW(34) checkpath = checkpath.Replace(" ", "") Dim cmd1 As String = "/Create /SC HOURLY /TN " & ChrW(34) & "ProSec Security Check" & ChrW(34) & " /TR " & checkpath & " /RL HIGHEST" Process.Start("SchTasks.exe", cmd1)
It does create a schedule task. The problem now is still the path of the app, currently it is:-
"C:\Users\Admin\Documents\VisualStudio2010\Projects\Tester-Sec\Tester-Sec\bin\Debug\Checks.exe"
The space after Visual and Studio have been removed due to string.replace.
But the task will not start because it wont find a folder "VisualStudio2010", the actual folder name is with space "Visual Studio 2010".
In order to clarify that infact this is the actual problem. I went to task scheduler console and manually browsed the Checks.exe application and then the task started running properly.
I need some workaround to infact provide spaces but schtask should not comprehend it as argument and put it in the arguments box.
Why are you using chr(34) in your checkpath variable? Trying getting rid of it. I usually would do something like this for you checkpath variable:
Dim checkpath as string
checkpath = Application.Startuppath + "\Checks.exe"
Have you tried adding Chr(34) to the checkpath variable at the end of the cmd1 string?
Dim cmd1 As String = "/Create /SC HOURLY /TN " & Chr(34) & "ProSec Security Check" & Chr(34) & " /TR " & Chr(34) & checkpath & Chr(34)& " /RL HIGHEST"
From what I know command line programs can be a little tricky and require you to quote a programs path. Command Line programs can be a pain in the neck sometimes with VB.NET.
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
Saturday, November 30, 2013 7:04 PM | 1 vote
The Thinker is right, you need quotes around the programs path if it has a space in it anywhere...such as with "Visual Studio 2010" has 2 spaces in it...you can't get rid of the spaces or replace them with another character...but if you enclose it in quotes either using Chr(34) or """ it will work...
Example:
Dim
var AsString= """C:\Space Test.exe"""
This would have quotes around the path, one quote " will open the string, a double quote "" will leave one in as part of the string so the variable would end up being "C:\Space Test.exe" including the " and " at the beginning and end.
Saturday, November 30, 2013 10:57 PM
So as you can see the first space is after the word Visual. So the task created reads it like this. Look at the image below:-
I seem to recall reading that if you use the "Start in" then the spaces will work: you would then just need the program name in the "Program/script" entry.
HTH,
Andrew
Sunday, December 1, 2013 7:08 AM
The Thinker is right, you need quotes around the programs path if it has a space in it anywhere...such as with "Visual Studio 2010" has 2 spaces in it...you can't get rid of the spaces or replace them with another character...but if you enclose it in quotes either using Chr(34) or """ it will work...
Example:
Dim
var AsString= """C:\Space Test.exe"""
This would have quotes around the path, one quote " will open the string, a double quote "" will leave one in as part of the string so the variable would end up being "C:\Space Test.exe" including the " and " at the beginning and end.
See here the spaces are after the words Visual and Studio. But once the application is ready for deploying the user's installation path may vary. For example it can be C:/Program Files/Another folder/checks.exe
So now you can exactly understand why I need this specific method to work.
Sunday, December 1, 2013 7:18 AM
So as you can see the first space is after the word Visual. So the task created reads it like this. Look at the image below:-
I seem to recall reading that if you use the "Start in" then the spaces will work: you would then just need the program name in the "Program/script" entry.
HTH,
Andrew
I just rechecked schtasks. There is no "Start in" parameter for schtasks.
Monday, December 2, 2013 10:16 AM
So far what is working is this:-
Dim checkpath As String = "" & Application.StartupPath & "\Checks.exe""" Dim cmd1 As String = "/Create /SC HOURLY /TN ""ProSec Security Check"" /TR """ & checkpath & " /RL HIGHEST" Process.Start("SchTasks.exe", cmd1)
But the problem is when Application.StartupPath = "C:\Users\Admin\Documents\Visual Studio 2010\Projects\Tester-Sec\Tester-Sec\bin\Debug"
So as you can see the first space is after the word Visual. So the task created reads it like this. Look at the image below:-
Hi,
I have created a sample to test with following code similar witn yours:
Try
Dim pr As New Process
pr.StartInfo.FileName = "schtasks.exe"
pr.StartInfo.Arguments = "/Create /SC HOURLY /TN ""My Test App"" /TR ""e:\test space\CopyItSelf.EXE"" /RL HIGHEST"
pr.Start()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
And the following image shows the result:
Although it shows the other part after a space in "Add arguments(optional)", but it still works fine.
Does that task works in your side?
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Monday, December 2, 2013 10:30 AM
So far what is working is this:-
Dim checkpath As String = "" & Application.StartupPath & "\Checks.exe""" Dim cmd1 As String = "/Create /SC HOURLY /TN ""ProSec Security Check"" /TR """ & checkpath & " /RL HIGHEST" Process.Start("SchTasks.exe", cmd1)
But the problem is when Application.StartupPath = "C:\Users\Admin\Documents\Visual Studio 2010\Projects\Tester-Sec\Tester-Sec\bin\Debug"
So as you can see the first space is after the word Visual. So the task created reads it like this. Look at the image below:-
Hi,
I have created a sample to test with following code similar witn yours:
Try Dim pr As New Process pr.StartInfo.FileName = "schtasks.exe" pr.StartInfo.Arguments = "/Create /SC HOURLY /TN ""My Test App"" /TR ""e:\test space\CopyItSelf.EXE"" /RL HIGHEST" pr.Start() Catch ex As Exception MsgBox(ex.ToString()) End Try
And the following image shows the result:
Although it shows the other part after a space in "Add arguments(optional)", but it still works fine.
Does that task works in your side?
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
For me the application doesn't start. When I goto "History" tab of the task I can see the error log saying executable not found or something like that. When I manually browse the application and when the whole application path is in the Program/Script textbox my application starts properly.
Tuesday, December 3, 2013 1:22 AM
Hi,
Glad to receive your reply.
1. Is the version of your OS Win7 or Win8?
2. Would you mind sharing the whole path of yours?
If there's any other information that you think may be helpful, we'd appreciate getting that.
I will test it in my side.
Regards.
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Tuesday, December 3, 2013 2:19 PM
Hi,
Glad to receive your reply.
1. Is the version of your OS Win7 or Win8?
2. Would you mind sharing the whole path of yours?
If there's any other information that you think may be helpful, we'd appreciate getting that.
I will test it in my side.
1) Windows 7.
2) C:\Users\Admin\Documents\Visual Studio 2010\Projects\Tester-Sec\Tester-Sec\bin\Debug\Checks.exe
The only information that I would like to provide is that this is a console application which will run every hour which will be located in the same folder of the MAIN application. Now the user can install the MAIN application in any path. So it is necessary for me to use Application.StartupPath in order to get the path of the console application. Now in Application.StartupPath it may or may not have spaces depending on the user system.
Tuesday, December 3, 2013 3:55 PM
Hi,
Glad to receive your reply.
1. Is the version of your OS Win7 or Win8?
2. Would you mind sharing the whole path of yours?
If there's any other information that you think may be helpful, we'd appreciate getting that.
I will test it in my side.
1) Windows 7.
2) C:\Users\Admin\Documents\Visual Studio 2010\Projects\Tester-Sec\Tester-Sec\bin\Debug\Checks.exe
The only information that I would like to provide is that this is a console application which will run every hour which will be located in the same folder of the MAIN application. Now the user can install the MAIN application in any path. So it is necessary for me to use Application.StartupPath in order to get the path of the console application. Now in Application.StartupPath it may or may not have spaces depending on the user system.
star email your solution and I will take a look at it (jefferycarlson@gmail.com) and see how it behaves after deployment. I have schtasks because I have home premium so I can test it out. Note: sometimes some dotnet programs install to a users temp folder instead of program files). Their is another method to get the location or path the executable is in besides application.startuppath (I use the second method for dlls) but I do not remember where it was in my myriad of code right now.
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
Tuesday, December 3, 2013 4:17 PM
Hi,
Glad to receive your reply.
1. Is the version of your OS Win7 or Win8?
2. Would you mind sharing the whole path of yours?
If there's any other information that you think may be helpful, we'd appreciate getting that.
I will test it in my side.
1) Windows 7.
2) C:\Users\Admin\Documents\Visual Studio 2010\Projects\Tester-Sec\Tester-Sec\bin\Debug\Checks.exe
The only information that I would like to provide is that this is a console application which will run every hour which will be located in the same folder of the MAIN application. Now the user can install the MAIN application in any path. So it is necessary for me to use Application.StartupPath in order to get the path of the console application. Now in Application.StartupPath it may or may not have spaces depending on the user system.
star email your solution and I will take a look at it (jefferycarlson@gmail.com) and see how it behaves after deployment. I have schtasks because I have home premium so I can test it out. Note: sometimes some dotnet programs install to a users temp folder instead of program files). Their is another method to get the location or path the executable is in besides application.startuppath (I use the second method for dlls) but I do not remember where it was in my myriad of code right now
Dotnet programs get installed WHERE THE AUTHOR specifies it to be deployed or gives the user the permission to set up the path of installation which is in the normal case. Now it doesnt matter where my console application is located even as you said if I change my path of the console application to the temp user still I can face the same problem,
For instance, C:\Users\My spaced username\AppData\Roaming\Checks.exe
Again the above path's username can be anything with or without space and I can face the same problem.
As far as emailing the application, I don't see it apt. The code that I am using have been provided and the issue has been put forward as elaborately as possible.
I would appreciate if you could provide a solution to this.
Tuesday, December 3, 2013 5:23 PM
Hi,
Glad to receive your reply.
1. Is the version of your OS Win7 or Win8?
2. Would you mind sharing the whole path of yours?
If there's any other information that you think may be helpful, we'd appreciate getting that.
I will test it in my side.
1) Windows 7.
2) C:\Users\Admin\Documents\Visual Studio 2010\Projects\Tester-Sec\Tester-Sec\bin\Debug\Checks.exe
The only information that I would like to provide is that this is a console application which will run every hour which will be located in the same folder of the MAIN application. Now the user can install the MAIN application in any path. So it is necessary for me to use Application.StartupPath in order to get the path of the console application. Now in Application.StartupPath it may or may not have spaces depending on the user system.
star email your solution and I will take a look at it (jefferycarlson@gmail.com) and see how it behaves after deployment. I have schtasks because I have home premium so I can test it out. Note: sometimes some dotnet programs install to a users temp folder instead of program files). Their is another method to get the location or path the executable is in besides application.startuppath (I use the second method for dlls) but I do not remember where it was in my myriad of code right now
Dotnet programs get installed WHERE THE AUTHOR specifies it to be deployed or gives the user the permission to set up the path of installation which is in the normal case. Now it doesnt matter where my console application is located even as you said if I change my path of the console application to the temp user still I can face the same problem,
For instance, C:\Users\My spaced username\AppData\Roaming\Checks.exe
Again the above path's username can be anything with or without space and I can face the same problem.
As far as emailing the application, I don't see it apt. The code that I am using have been provided and the issue has been put forward as elaborately as possible.
I would appreciate if you could provide a solution to this.
I have it working completely on my computer. here is a screenshot for task scheduler:
Below is my code:
Try
Dim pr As New Process
Dim a As Integer
pr = Process.Start("C:\Windows\System32\cmd.exe")
System.Threading.Thread.Sleep(2000)
a = pr.Id
AppActivate(a)
My.Computer.Keyboard.SendKeys("schtasks.exe", True)
My.Computer.Keyboard.SendKeys("/Create /SC WEEKLY /TN MyTestApp /TR " + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) + " /RL HIGHEST", True)
My.Computer.Keyboard.SendKeys("{Enter}", True)
' pr.StartInfo.FileName = "schtasks.exe"
' pr.StartInfo.Arguments = "/Create /SC HOURLY /TN My Test App /TR" + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) '+ "/RL HIGHEST"
Catch ex As Exception
MsgBox(ex.ToString())
End Try
The problem was the spaces and improper characters (I already stated the quotes above in a previous post).
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
Tuesday, December 3, 2013 5:44 PM
I have it working completely on my computer. here is a screenshot for task scheduler:
Below is my code:
Try Dim pr As New Process Dim a As Integer pr = Process.Start("C:\Windows\System32\cmd.exe") System.Threading.Thread.Sleep(2000) a = pr.Id AppActivate(a) My.Computer.Keyboard.SendKeys("schtasks.exe", True) My.Computer.Keyboard.SendKeys("/Create /SC WEEKLY /TN MyTestApp /TR " + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) + " /RL HIGHEST", True) My.Computer.Keyboard.SendKeys("{Enter}", True) ' pr.StartInfo.FileName = "schtasks.exe" ' pr.StartInfo.Arguments = "/Create /SC HOURLY /TN My Test App /TR" + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) '+ "/RL HIGHEST" Catch ex As Exception MsgBox(ex.ToString()) End Try
It was the spaces and improper characters (I already stated the quotes above in a previous post).
I tried the exact code on my system, and like I always said it DOES create the task. But the problem is in the image below:-
Now if you simply right click the task and click RUN. Firefox won't start because the path of the program is like in the image above. THAT is the same problem I have.
Tuesday, December 3, 2013 6:50 PM
I have it working completely on my computer. here is a screenshot for task scheduler:
Below is my code:
Try Dim pr As New Process Dim a As Integer pr = Process.Start("C:\Windows\System32\cmd.exe") System.Threading.Thread.Sleep(2000) a = pr.Id AppActivate(a) My.Computer.Keyboard.SendKeys("schtasks.exe", True) My.Computer.Keyboard.SendKeys("/Create /SC WEEKLY /TN MyTestApp /TR " + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) + " /RL HIGHEST", True) My.Computer.Keyboard.SendKeys("{Enter}", True) ' pr.StartInfo.FileName = "schtasks.exe" ' pr.StartInfo.Arguments = "/Create /SC HOURLY /TN My Test App /TR" + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) '+ "/RL HIGHEST" Catch ex As Exception MsgBox(ex.ToString()) End Try
It was the spaces and improper characters (I already stated the quotes above in a previous post).
I tried the exact code on my system, and like I always said it DOES create the task. But the problem is in the image below:-
Now if you simply right click the task and click RUN. Firefox won't start because the path of the program is like in the image above. THAT is the same problem I have.
I get close but everytime I Input program files the x86 version it trims out the ( and ) characters:
Try
Dim pr As New Process
Dim a As Integer
pr = Process.Start("C:\Windows\System32\cmd.exe")
System.Threading.Thread.Sleep(2000)
a = pr.Id
AppActivate(a)
My.Computer.Keyboard.SendKeys("schtasks.exe /Create /SC WEEKLY /TN MyTestApp23 /TR " + Chr(34) + Chr(39) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(39) + Chr(34), True)
'My.Computer.Keyboard.SendKeys("), True)
My.Computer.Keyboard.SendKeys("{Enter}", True)
' pr.StartInfo.FileName = "schtasks.exe"
' pr.StartInfo.Arguments = "/Create /SC HOURLY /TN My Test App /TR" + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) '+ "/RL HIGHEST"
Catch ex As Exception
MsgBox(ex.ToString())
End Try
Task scheduler is making me mad because it truncates the ( and ) characters if I send them through the command line with visual studio.
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
Tuesday, December 3, 2013 6:55 PM
I have it working completely on my computer. here is a screenshot for task scheduler:
Below is my code:
Try Dim pr As New Process Dim a As Integer pr = Process.Start("C:\Windows\System32\cmd.exe") System.Threading.Thread.Sleep(2000) a = pr.Id AppActivate(a) My.Computer.Keyboard.SendKeys("schtasks.exe", True) My.Computer.Keyboard.SendKeys("/Create /SC WEEKLY /TN MyTestApp /TR " + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) + " /RL HIGHEST", True) My.Computer.Keyboard.SendKeys("{Enter}", True) ' pr.StartInfo.FileName = "schtasks.exe" ' pr.StartInfo.Arguments = "/Create /SC HOURLY /TN My Test App /TR" + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) '+ "/RL HIGHEST" Catch ex As Exception MsgBox(ex.ToString()) End Try
It was the spaces and improper characters (I already stated the quotes above in a previous post).
I tried the exact code on my system, and like I always said it DOES create the task. But the problem is in the image below:-
Now if you simply right click the task and click RUN. Firefox won't start because the path of the program is like in the image above. THAT is the same problem I have.
I get close but everytime I Input program files the x86 version it trims out the ( and ) characters:
Try Dim pr As New Process Dim a As Integer pr = Process.Start("C:\Windows\System32\cmd.exe") System.Threading.Thread.Sleep(2000) a = pr.Id AppActivate(a) My.Computer.Keyboard.SendKeys("schtasks.exe /Create /SC WEEKLY /TN MyTestApp23 /TR " + Chr(34) + Chr(39) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(39) + Chr(34), True) 'My.Computer.Keyboard.SendKeys("), True) My.Computer.Keyboard.SendKeys("{Enter}", True) ' pr.StartInfo.FileName = "schtasks.exe" ' pr.StartInfo.Arguments = "/Create /SC HOURLY /TN My Test App /TR" + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) '+ "/RL HIGHEST" Catch ex As Exception MsgBox(ex.ToString()) End Try
Task scheduler is making me mad because it truncates the ( and ) characters if I send them through the command line with visual studio.
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
If I use a normal path string such as "c:\program files\dvd maker\dvd maker.exe" the above works. However, it does not if you use ( and ) in the path string. Microsoft screwed up somewhere because task scheduler does not accept weird paths unless I forgot a setting in visual studio somewhere. If i do program files (x86) from the command line manually though it works. Edit: heres a picture:
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
Wednesday, December 4, 2013 6:55 AM
I have it working completely on my computer. here is a screenshot for task scheduler:
Below is my code:
Try Dim pr As New Process Dim a As Integer pr = Process.Start("C:\Windows\System32\cmd.exe") System.Threading.Thread.Sleep(2000) a = pr.Id AppActivate(a) My.Computer.Keyboard.SendKeys("schtasks.exe", True) My.Computer.Keyboard.SendKeys("/Create /SC WEEKLY /TN MyTestApp /TR " + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) + " /RL HIGHEST", True) My.Computer.Keyboard.SendKeys("{Enter}", True) ' pr.StartInfo.FileName = "schtasks.exe" ' pr.StartInfo.Arguments = "/Create /SC HOURLY /TN My Test App /TR" + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) '+ "/RL HIGHEST" Catch ex As Exception MsgBox(ex.ToString()) End Try
It was the spaces and improper characters (I already stated the quotes above in a previous post).
I tried the exact code on my system, and like I always said it DOES create the task. But the problem is in the image below:-
Now if you simply right click the task and click RUN. Firefox won't start because the path of the program is like in the image above. THAT is the same problem I have.
I get close but everytime I Input program files the x86 version it trims out the ( and ) characters:
Try Dim pr As New Process Dim a As Integer pr = Process.Start("C:\Windows\System32\cmd.exe") System.Threading.Thread.Sleep(2000) a = pr.Id AppActivate(a) My.Computer.Keyboard.SendKeys("schtasks.exe /Create /SC WEEKLY /TN MyTestApp23 /TR " + Chr(34) + Chr(39) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(39) + Chr(34), True) 'My.Computer.Keyboard.SendKeys("), True) My.Computer.Keyboard.SendKeys("{Enter}", True) ' pr.StartInfo.FileName = "schtasks.exe" ' pr.StartInfo.Arguments = "/Create /SC HOURLY /TN My Test App /TR" + Chr(34) + "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" + Chr(34) '+ "/RL HIGHEST" Catch ex As Exception MsgBox(ex.ToString()) End Try
Task scheduler is making me mad because it truncates the ( and ) characters if I send them through the command line with visual studio.
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
If I use a normal path string such as "c:\program files\dvd maker\dvd maker.exe" the above works. However, it does not if you use ( and ) in the path string. Microsoft screwed up somewhere because task scheduler does not accept weird paths unless I forgot a setting in visual studio somewhere. If i do program files (x86) from the command line manually though it works. Edit: heres a picture:
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
This is exactly what I told. I am not able to give the path from Visual Studio. I need this definitely to work.
Wednesday, December 4, 2013 1:33 PM
Hi,
using Win7 32 bit,TaskScheduler V1.0, VB.NET 2010 this is working like a charme on my side:
Dim pr As New System.Diagnostics.Process pr.StartInfo.FileName = "schtasks.exe" pr.StartInfo.Arguments = "/Create /SC HOURLY /TN ""My Test App"" /TR ""'" & Application.StartupPath & "\Checks.exe" & "'""" pr.Start()
So the little tricky part here is that you need to add a single quot also before and after the filename which contains a space in it.
Hannes
If you have got questions about this, just ask.
In a perfect world,
users would never enter data in the wrong form,
files they choose to open would always exist
and code would never have bugs.
PERFECT!
I had tried with single quotes before similar to that when you pass SQL statements but didn't work at that time. But right now it works perfectly.
Thanks a ton! And a single quote can definitely ruin hours of time. LOL!
Wednesday, December 4, 2013 3:07 PM
Hi,
using Win7 32 bit,TaskScheduler V1.0, VB.NET 2010 this is working like a charme on my side:
Dim pr As New System.Diagnostics.Process pr.StartInfo.FileName = "schtasks.exe" pr.StartInfo.Arguments = "/Create /SC HOURLY /TN ""My Test App"" /TR ""'" & Application.StartupPath & "\Checks.exe" & "'""" pr.Start()
So the little tricky part here is that you need to add a single quot also before and after the filename which contains a space in it.
Hannes
If you have got questions about this, just ask.
In a perfect world,
users would never enter data in the wrong form,
files they choose to open would always exist
and code would never have bugs.PERFECT!
I had tried with single quotes before similar to that when you pass SQL statements but didn't work at that time. But right now it works perfectly.
Thanks a ton! And a single quote can definitely ruin hours of time. LOL!
I got it working too though. :/. I tested my last post with his and it works the same.
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
Wednesday, December 4, 2013 3:09 PM
Hi,
using Win7 32 bit,TaskScheduler V1.0, VB.NET 2010 this is working like a charme on my side:
Dim pr As New System.Diagnostics.Process pr.StartInfo.FileName = "schtasks.exe" pr.StartInfo.Arguments = "/Create /SC HOURLY /TN ""My Test App"" /TR ""'" & Application.StartupPath & "\Checks.exe" & "'""" pr.Start()
So the little tricky part here is that you need to add a single quot also before and after the filename which contains a space in it.
Hannes
If you have got questions about this, just ask.
In a perfect world,
users would never enter data in the wrong form,
files they choose to open would always exist
and code would never have bugs.PERFECT!
I had tried with single quotes before similar to that when you pass SQL statements but didn't work at that time. But right now it works perfectly.
Thanks a ton! And a single quote can definitely ruin hours of time. LOL!
I got it working too though. :/. I tested my last post with his and it works the same.
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr
P.S. you can mark multiple answers if it multiple people have something that works.
Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to suffering - Yoda. Blog - http://www.computerprofessions.co.nr