Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created one windows application which will create a folder and write file into that.



i created task scheduler in windows server 2012 R2 . as below
2. i had configure to the account which is having admin access
3.

Problem:
1. The task scheduler is execute the exe command . but the problem is its not opening the form so that the vb script not find the button to click so that the task get started.
2. i am not sure where is the problem. but what i feel is to hit enter button from vb script the form has to be open in system.

Note:when ever i tried and double click on batch file its opening the form and clicking on button. working as expected .

What I have tried:

1.created task scheduler. where i have given path of batch file . what it does is , batch file calls a vb script and the vb script calls exe file and press enter button so that the exe will start executing.
2. Below is the congfiguration of task scheduler
Step 1: Create a batch file you wish to run and place it under a folder where you have enough permissions. For example under C drive.

Step 2: Click on Start and under search, type in Task and click open Task Scheduler.

Step 3: Select Create Basic Task from the Action pane on the right of the window.

Step 4: Under Create Basic Task, type in the name you like and click Next.

Step 5: From the Trigger select the option you like and click Next.

I chose Daily and clicked Next, which brought me to this screen.

Step 6: Then click on Start a Program and click Next.

Step 7: Now click on Browser and select the batch file you like to run.

Step 8: Finally, click on Finish to create the Task.

Step 8: Click on Run with Highest privilege then click OK.



My Vb script look like below
<pre lang="vb">
Dim shell

set shell = WScript.CreateObject("WScript.Shell")

shell.Run "\\10.248.8.162\Shared\Sunil\DailyReporting\RunTool\Tool\ProductionMonitoringTool.exe"

shell.AppActivate "MonitoringForm"

WScript.Sleep 2000

shell.SendKeys "Going to press enter"
shell.SendKeys "{ENTER}"
shell.SendKeys "pressed enter"
Posted
Updated 16-Apr-19 3:34am

1 solution

It's not entirely clear what kind of app you've written. Is this a Windows Forms app you wrote or a Console app? Or are you running some other built-in Windows executable and trying to manipulate it with your app? What button are you talking about? What's the story with this VBScript and how does it relate to everything else?

Scheduler jobs run under a separate desktop. You're not going to see any user interface from any application launched by the Scheduler.

A VBScript isn't going to be able to "push a button" on a desktop that never receives user input.

Also, in order to run this job with network access, the account you setup the Scheduler job to run under MUST have access to the network share, just like any other user who would. Running this job under the LocalSystem (SYSTEM) account will NOT work. It won't have access to network shares.
 
Share this answer
 
Comments
johannesnestler 17-Apr-19 10:32am    
I thought the same - an easy solution maybe just to use commandline-arguments and start the app in an "console" mode which does the Job without the form. But OP didn't give enough relevant Information as you pointed out...
Member 12315889 19-Apr-19 2:28am    
Its windows application, what it does is , it use to open windows form and in that form we have one button which has be click .this work done by batch file.
its not cosole application

Scheduler jobs run under a separate desktop. You're not going to see any user interface from any application launched by the Scheduler.

if the above stament is true then could you please let me know how could i will find the button to click?
Dave Kreskowiak 19-Apr-19 9:01am    
The problem is that there is no way for the "batch file" to find a button and press it when that button cannot ever have the input focus.

You made a mistake by making this a Windows Forms app instead of a console app.

Of course, I'm making an assumption there because I still don't know what this app does, what the batch file does, what the code looks like for either, and why you have to "push a button".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900