i have a windows forms application to backup certain files.
Normally you hit the button "Start Backup" and the programm
will do whatever is selected as an option.
Now i have implemented via Task Sceduler DLL the possibility
to do the backup on a desired day and time via a datetimepicker
object.
So far i only found out how to register the the programm.exe
in Windows and it also starts up on the chosen time.
My question now is how would it be possible to be able to execute
the "Start Backup" button via automation or a script? All other needed
parameters for the programm are stored in Settings.Default values.
Code from the Task Scheduler, maybe there is a shorter way to solve
the problem?
private void futureBackup_Click(object sender, EventArgs e)
{
dateTimePicker1.Format = DateTimePickerFormat.Time;
TaskService ts = new TaskService();
TaskDefinition td = ts.NewTask();
Trigger t = new TimeTrigger();
t.StartBoundary = System.DateTime.Now.Date
+this.dateTimePicker1.Value.TimeOfDay;
td.Triggers.Add(t);
string path1 = Desktop + #"\Desktop\Release\Backup.exe";
td.Actions.Add(new ExecAction(path1, null, null));
ts.RootFolder.RegisterTaskDefinition("XBackupX", td);
ts.BeginInit();
}
I found the UI Automation in Visual Studio but i am not exactly sure if that's what can fix the "problem"!?!
Thank you in advance
for now the easiest way i came up with is to have
2 programm exe files... 2nd one is called backup_s.exe
which then is added to the task scheduler in windows.
only difference between the 2 codes is _s loads the last
options automatically from an xml file then executes the
start backup by trigger event and closes itself after 1
minute.
Related
I'm new to NetSuite and have been tasked with integrating another system with NetSuite. I've created a User Event script that needs to run against multiple NetSuite events. The deployment interface seems to only let me assign the script to Create OR Edit, but not both. Is this not possible or what am I doing wrong?
Thanks,
You can define the events on which the UE script runs within the script, and leave the event type assignment in the deployment record blank.
Firstly, if you leave the event type blank in the UI and don't include logic withing the script to limit when it runs, it will be triggered on all event types (create, edit etc) whenever the triggering event occurs (beforeLoad, beforeSubmit, afterSubmit).
Selecting the event type in the UI is an easy shortcut to limiting when a script runs without having to worry about additional script logic; however, for maximum flexibility you can use script logic as follows or modify to suit your needs (in SS2.0):
function beforeSubmit(scriptContext) {
log.debug('type', scriptContext.type);
if (scriptContext.type !== scriptContext.UserEventType.CREATE) {
log.error('Exiting script', 'Context type is ' + scriptContext.type);
return;
}
//Do your work here
}
I write a application use notifycation on winphone 8. My application require send URI continuous to server every 30 seconds. My problem, i used reminder of winphone, but it can't use webbrowser call request in reminder.
My code:
public MainPage()
{
InitializeComponent();
var reminder = new Reminder("MyReminder")
{
Content = "Sending uri to server...",
BeginTime = DateTime.Now.AddSeconds(30),
webBrowser1.Navigate(new Uri("http://nhomxe.vn/device_register?uri="http://...", UriKind.Absolute));
};
ScheduledActionService.Add(reminder);
}
I think you're misunderstanding what the Reminder class is for and how to use it.
The Reminder class will display a prompt to the user with a piece of shell UI and allow them to tap on it to open your app. (Similar to an Alarm which also displays UI and allows you to customize the sound that is played but doesn't support a direct link to the app.)
The code you have written doesn't compile because you are writing the code to execute inside the object initializer which won't work. You also appear to have a string concatenation issue but this may just be a spurious quote(").
If you just want to make a request to a URL endpoint you also don't need to load it in a browser.
Assuming that you're wanting to send a message to your server every 30 seconds while the app is running then you could just do this with a Timer.
Like this:
var timer = new Timer(
state => new WebClient().DownloadStringAsync(new Uri("http://blah.blah/")),
null,
TimeSpan.FromSeconds(30),
TimeSpan.FromSeconds(30));
Obviously add error handling, etc.
It is not possible to have your code run every 30 seconds when your app is not running. If you want to do something when your app is not in the foreground then you need to look at using Background Agents.
You can use periodic task if you want to fetch information every 30 mins.
Currently developing a connector DLL to HP's Quality Center. I'm using their (insert expelative) COM API to connect to the server. An Interop wrapper gets created automatically by VStudio.
My solution has 2 projects: the DLL and a tester application - essentially a form with buttons that call functions in the DLL. Everything works well - I can create defects, update them and delete them. When I close the main form, the application stops nicely.
But when I call a function that returns a list of all available projects (to fill a combo box), if I close the main form, VStudio still shows the solution as running and I have to stop it.
I've managed to pinpoint a single function in my code that when I call, the solution remains "hung" and if I don't, it closes well. It's a call to a property in the TDC object get_VisibleProjects that returns a List (not the .Net one, but a type in the COM library) - I just iterate over it and return a proper list (that I later use to fill the combo box):
public List<string> GetAvailableProjects()
{
List<string> projects = new List<string>();
foreach (string project in this.tdc.get_VisibleProjects(qcDomain))
{
projects.Add(project);
}
return projects;
}
My assumption is that something gets retained in memory. If I run the EXE outside of VStudio it closes - but who knows what gets left behind in memory?
My question is - how do I get rid of whatever calling this property returns? Shouldn't the GC handle this? Do I need to delve into pointers?
Things I've tried:
getting the list into a variable and setting it to null at the end of the function
Adding a destructor to the class and nulling the tdc object
Stepping through the tester function application all the way out, whne the form closes and the Main function ends - it closes, but VStudio still shows I'm running.
Thanks for your assistance!
Try to add these 2 lines to post-build event:
call "$(DevEnvDir)..\Tools\vsvars32.bat"
editbin.exe /NXCOMPAT:NO "$(TargetPath)"
Have you tried manually releasing the List object using System.Runtime.InteropServices.Marshal.ReleaseComObject when you are finished with it ?
I suspect some dangling threads.
When this happens, pause the process in the debugger and see what threads are still around.
May be try to iterate the list manually using it's count and Item properties instead of using it's iterator, some thing like:
for (int i=1; i <= lst.Count ; ++i)
{
string projectName = lst.Item(i);
}
It might be the Iterator that keeps it alive and not the list object itself, if not using an iterator might not have a problem.
So I'm debugging some websites (one from trunk, one from branch) running locally, in separate apppools. I have trunk and branch solutions open in two VS instances. I'd like to debug trunk in one, and branch in the other. I'd like to know if there's a way to know which application pool each w3wp.exe is serving, to know which one is which when attaching the debugger.
Update: the point of this is to write a macro within VS to then let me have a button (per app-pool that is interesting) which will be clickable to attach the debugger to. So solutions should preferably not involve other programs.
Update2: this is on Windows 7 against IIS7.
Below is my core macro. Write a few one-line subs calling it, like AttachToW3wp("DefaultAppPool") naming each app pool you’re interested in, and make buttons and hotkeys for them.
Private Sub AttachToW3wp(ByVal appPoolName As String)
Const processName As String = "w3wp.exe"
Dim userName As String = String.Format("IIS APPPOOL\{0}", appPoolName)
Try
Dim debugger As EnvDTE90.Debugger3 = CType(DTE.Debugger, EnvDTE90.Debugger3)
'debugger.DetachAll()
Dim transport As EnvDTE80.Transport = debugger.Transports.Item("Default")
Dim qualifier As String = Environment.MachineName '= My.Computer.Name
Dim engines(3) As EnvDTE80.Engine
engines(0) = transport.Engines.Item("Managed")
engines(1) = transport.Engines.Item("Script")
engines(2) = transport.Engines.Item("T-SQL")
Dim successMessage As String = String.Empty
For Each process As EnvDTE80.Process2 In debugger.GetProcesses(transport, qualifier)
With process
Dim fi As New System.IO.FileInfo(.Name)
If fi.Name = processName AndAlso (String.Compare(.UserName, 0, userName, 0, Len(userName), True) = 0) Then
If .IsBeingDebugged Then Throw New Exception(String.Format("{0} {1} is already attached to a debugger.", processName, userName))
process.Attach2(engines)
successMessage = String.Format("Attached to {0} for {1} ({2})", processName, userName, .ProcessID)
Exit For
End If
End With
Next
If successMessage = String.Empty Then
Throw New Exception(String.Format("{0} {1} not found.", processName, userName))
Else
Trace.WriteLine(successMessage)
End If
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
Another option would be the WADA - W3WP Advanced Attacher available in the Visual Studio Gallery. I found it by searching in the Online Gallery of Extension Manager for "attach worker".
Look at the answers to this question. There are built in scripts you can run from a command window to do this.
If you can execute a request on each branch, you could use something like Process Explorer or Task Manager to see which ID is which possibly as one may be taking up CPU cycles that is currently processing a request assuming you can get such separation.
You can use task manager to view the user name under which the process is running (which in general is the same as the application pool name) and the process ID, but you have to turn on these columns in task manager, and also the process name has to be the same as the application pool (which is the default as far as I know).
Also note that all methods listed on this page might only display the processes that are currently running, which means that if your particular process has shut down due to idle time you have first to use the site in order to bring the process up in the list, and in your case it means you should first access all sites to make sure that the process associated with them is runing.
We are trying to develop a small application that can monitor the programs/processes that are executing in a windows machine.
If the program/process is not supposed to run, it should be blocked. It works similar to an antivirus.
This is the basic idea.
I want to know the ways to hook into the OS to get notified about every single program/process trying to run in the machine.
The easiest way is to use WMI. Specifically monitor the Win32_ProcessStartTrace. This is better than Win32_Process, because it is setup to use events whereas Win32_Process requires polling which is more CPU intensive. Below is how to do it in C#. First make sure that System.Management is setup as a reference for your project.
public System.Management.ManagementEventWatcher mgmtWtch;
public Form1()
{
InitializeComponent();
mgmtWtch = new System.Management.ManagementEventWatcher("Select * From Win32_ProcessStartTrace");
mgmtWtch.EventArrived += new System.Management.EventArrivedEventHandler(mgmtWtch_EventArrived);
mgmtWtch.Start();
}
void mgmtWtch_EventArrived(object sender, System.Management.EventArrivedEventArgs e)
{
MessageBox.Show((string)e.NewEvent["ProcessName"]);
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
mgmtWtch.Stop();
}
The code will generate a messagebox everytime you launch a new process. From there you can check a whitelist/blacklist and act appropriately.
I havn't tried geting real-time notification. How ever, Here is how to get running processes in C#
using System.Diagnostics;
//Somewhere in your method
Process[] runningList = Process.GetProcesses();
foreach(Process p in runningList){
Console.WriteLine("Process: {0} ID: {1}", p.ProcessName, p.Id);
}
You can also use the following props of a process
StartTime - Shows the time the process started
TotalProcessorTime - Shows the amount of CPU time the process has taken
Threads - gives access to the collection of threads in the process
I would check up the Win32-api SetWindowsHookEx with the constant WH_GETMESSAGE to add a callback to your program when a new window is being created.
http://pinvoke.net/default.aspx/user32.SetWindowsHookEx
Google that API and WH_GETMESSAGE to find out more.
Also check out the following articles/code librarys:
http://www.vbaccelerator.com/home/Vb/Code/Libraries/Hooks/vbAccelerator_Hook_Library/article.asp
http://www.codeproject.com/KB/DLL/hooks.aspx?fid=2061&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=76&select=726975