|
Off the top of my head...
You can set up a client/server application on the two machines respectively, and then send a certain message from the client program to the waiting server and depending on the message received have the server execute that particular command, whether it be shut down, log off, lock etc.
On the server to log off, shut down and junk, look into the windows api and pinvoke the needed functions to preform those operations. Off the top of my head to shut down is ExitWindowsEx , just poke around it shouldn't be hard to find.
But, once you log out remotely, you won't be able to log back in remotely. I don't think...
/\ |_ E X E GG
|
|
|
|
|
right thanks.. any one has an actual sample of a code of a form with a lock/unlock button on the client where i can log off or lock the client. Once i know how to do that locally, I should be able to do it remotely. thanks
|
|
|
|
|
Hi,
I have two Forms (A and B). When Form A is active I open Form B. I then want to run some code automatically in Form A when I close Form B. How do I do that?
Thanks,
Carl-Johan Larsson
|
|
|
|
|
I assume FormB is not modal - that is, you show it so that it floats but you can still use FormA ( you call Show instead of ShowDialog ). You need to create a function in FormA that looks like this:
private static void dlg_Closed(object sender, EventArgs e)
{
}
then before you show FormB in FormA, you do this ( assuming dlg is the name of your FormB class instance:
dlg.Closed += new EventHandler(dlg_Closed);
There is also a Closing event, which get's called BEFORE the form closes. Now add your code to the method you added to FormA.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Did the trick, Thanks Carl-Johan Larsson
|
|
|
|
|
|
Awesome! Thanks for the info. Looking forward to the Wintellect PowerThreading library I've heard to be in the works...
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
I'm writing a small app, and I have to prepare a form which will authenticate users. This is the code I wrote. The problem is I get exception in the marked line : "no value given for for on or more required parameters"
What is wrong with it?
Table name is users.
Column name is UserName
<br />
public void userExists(string username)<br />
{<br />
try<br />
{
string sqlFinduser = "SELECT COUNT(UserName) AS UserNameExists " +<br />
"FROM users " +<br />
"WHERE (UserName=" + username + ")";<br />
<br />
OleDbCommand cmdFindsqlFinduser = new OleDbCommand();<br />
<br />
cmdFindsqlFinduser.Connection = cnSurvey;<br />
cmdFindsqlFinduser.CommandType = CommandType.Text;<br />
cmdFindsqlFinduser.CommandText = sqlFinduser;<br />
<br />
cnSurvey.Open();<br />
<br />
int count = int.Parse(cmdFindsqlFinduser.ExecuteScalar().ToString()); <br />
<br />
bool exists = count != 0 ? true : false;<br />
<br />
cnSurvey.Close();<br />
<br />
}<br />
catch(Exception ex)<br />
{<br />
MessageBox.Show(ex.Message);<br />
}<br />
<br />
}<br />
<br />
TIA,
Ronen
|
|
|
|
|
That means that you have one or more names in your query that the database does not regognise.
You have forgotten the apostrophes around the value for username. The database will try to interpret the username as being an identifier, not a string.
---
b { font-weight: normal; }
|
|
|
|
|
How about changing
(UserName=" + username + ")"
to
(UserName='" + username + "')"
assume: username = "abc"
Current code: (UserName = abc)
Fixed code: (UserName = 'abc')
|
|
|
|
|
|
Hey everyone, a quick thanks for taking a look at this...
Basically, my problem is this... I have a "Core" library which contains a "Manager" component, and I want to use this component in C#. This component is written in C++, and here is the IDL file defining its type library.
<br />
import "unknwn.idl";<br />
<br />
[<br />
object,<br />
uuid(822A2EDE-09F1-45b8-B80E-A32F21415677),<br />
helpstring("Interface used by the Manager")<br />
]<br />
<br />
interface IManager : IUnknown<br />
{<br />
HRESULT GetAppName([out, size_is(, *pcMax)] char **ppAppName,<br />
[out] long *pcMax);<br />
<br />
HRESULT SetStatus([in] long cLength,<br />
[in, size_is(cLength)] char* id,<br />
[in] int s);<br />
};<br />
<br />
[<br />
uuid(AE068C74-0B8B-4041-8CA9-4A590DDDC382),<br />
helpstring("Core Component Library")<br />
]<br />
library Core<br />
{<br />
importlib("stdole32.tlb");<br />
importlib("stdole2.tlb");<br />
<br />
interface IManager;<br />
}<br />
Now, if I write a C++ app to use this component, doing this, it works great...
(Keep in mind, the component is registered in the registry and the DLL creates an instance of the component by using IClassFactory)
<br />
#include "stdafx.h"<br />
#include <objbase.h><br />
#import "Core.tlb"<br />
<br />
int main(int argc, char* argv[])<br />
{<br />
HRESULT hr = NULL;<br />
CLSID clsid;<br />
<br />
::CoInitialize(NULL);<br />
<br />
Core::IManager* pManager;<br />
hr = CLSIDFromProgID(OLESTR("Core.1"), &clsid);<br />
<br />
if(FAILED(hr))<br />
{<br />
cout << "DLL not installed correctly" << endl;<br />
}<br />
<br />
hr = ::CoCreateInstance(clsid, NULL, <br />
CLSCTX_ALL, __uuidof(Core::IManager), (void** )&pManager);<br />
<br />
<br />
if(SUCCEEDED(hr))<br />
{<br />
cout << "Found component!" << endl;<br />
<br />
}<br />
}<br />
No problem, it executes just fine, my C++ app easily uses the component.
Now, I try importing "Core.tlb" into .NET, by using tlbimp.exe, I get a useless managed assembly... After pouring through MSDN article after MSDN article, I've come to the conclusion that its possible to create a COM class wrapper? However, I've had no luck with that as well... This is all I've been able to come up with, but I know it doesn't work...
<br />
namespace Core<br />
{<br />
[Guid("822A2EDE-09F1-45b8-B80E-A32F21415677"),<br />
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]<br />
interface IManager<br />
{<br />
void GetAppName(<br />
[Out, MarshalAs(UnmanagedType.BStr)] string strAppname,<br />
[Out] int maxSize);<br />
<br />
void SetTestPointStatus(<br />
[In] int MaxLength,<br />
[In, MarshalAs(UnmanagedType.BStr)] string id,<br />
[In] int status);<br />
}<br />
<br />
[ComImport, Guid("AE068C74-0B8B-4041-8CA9-4A590DDDC382")]<br />
class CManager<br />
{<br />
}<br />
}<br />
Anyone have any suggestions? I've come to the conclusion that I really have no idea what I'm doing in C# as far as interop goes, I'm not a bad C# coder, but this just escapes me at the moment...
Anyway, thanks again for reading this
|
|
|
|
|
Hi!
In your C# project, just add a reference to your COM object (in project explorer, select "Add reference..." and find your COM class on the COM tab).
VS.NET will create the interop assembly and you can immediately use your COM class.
Typing "Core." should already give you intellisense for IManager, CManager and so on.
Regards,
mav
|
|
|
|
|
First, thank you very much for your advice...
Hmmm, I've tried that, but like I said, I don't really have that usable of an interop assembly... It only gives me Core::IManager, just the interface... Do I have to implement that interface, or write a wrapper for that? There are no class objects for me to instantiate... Some sites talk about coclasses, but I have none defined in my IDL file, and I'm not really sure what I'm doing as far as that... haha, am I just doing this wrong?
Thanks again
|
|
|
|
|
Ok, now that I've taken a second look at the IDL, there in fact isn't a CoClass defined, so all you'll get will be IManager. This is correct so far.
What puzzles me is that you claim that it does work with C++/CoCreateInstance...
I didn't find any class actually implementing IManager, so which class is created by the class factory?
mav
|
|
|
|
|
I have a program, it's a form, a GUI. I need it to close when I hit the x-button in the corner. It is still running in the processes after I close it. How do I permenantly kill the program?
I tried this:
private void ExitButton_Click(object sender, System.EventArgs e)
{
this.Close();
}
thanks very much!
|
|
|
|
|
You want to register on the Form_Closing event.
private void Form1_Closing(object sender, CancelEventArgs e)<br />
{<br />
if (should Not Close)<br />
e.Cancel = true;<br />
}
There are 10 kinds of people in the world.
Those that read binary...
...and those who don't.
|
|
|
|
|
I'm writing an app that needs to write to a database (database file...like mdf) with out having to install one (like SQL server or Access). Are there any examples on how to do this in C#?
What is the best practice for writing an app that needs database support but is not network aware?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
take a look at Firebird
www.firebirdsql.com
it kan be used in embedded mode
so u only need a dll (1,5MB) in the app folder and you have a full RDBMS
|
|
|
|
|
So do I need to download the .net data provider for framework 1.1? Or is there more to it?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
I've used VistaDB in the past. It has only a 500KB footprint, and a fully featured .NET data provider for use with ADO.NET.
Check http://www.vistadb.com[^].
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
You don't have to install Microsoft Access to use an Access database. The drivers come with windows.
---
b { font-weight: normal; }
|
|
|
|
|
So I can use access and just make my connection string point to a specific file?
Thanks
Tom Wright
tawright915@yahoo.com
|
|
|
|
|
Yes.
---
b { font-weight: normal; }
|
|
|
|
|
Hi,
How can I add a Delete button to a datagrid, to delete a row?
I added an Edit Command by , its working fine, but how to add a delete command?
Thanks
|
|
|
|