|
Hi All,
Anyone knows how to safely "Unplug or Eject Hardware" without having to click that green arrow icon on the system tray? I want to write an application using some window API to do it.
Normally that icon appear when i plug in my USB storage.
I have searched the web, some people use DeviceIOControl to eject, but it doesn't really remove the device as when i click the icon and "Stop USB Storage Device - Drive G:"
Can anyone enlighten me please? I refuse to believe that i cannot do this using some window APIs... Thanks!!
|
|
|
|
|
You will need the DDK to get the docs, headers, and libs.
The relevant functions are CM_Locate_DevNode() , CM_Query_And_Remove_SubTree() , and CM_Request_Device_Eject()
--Mike--
Personal stuff:: Ericahist | Homepage
Shareware stuff:: 1ClickPicGrabber | RightClick-Encrypt
CP stuff:: CP SearchBar v2.0.2 | C++ Forum FAQ
----
Pinky, are you pondering what I'm pondering?
I think so Brain, but how will we fit the hamster inside the accordion?
|
|
|
|
|
I added an Edit Box to my Dialog. i'd like it only accept numeric input. when a non-numeric key is pressed a warning dialog will apear. i mean, just after press the key, not after my button 'Subject' is pressed, the dialog appears.
Hello World
|
|
|
|
|
If you only want it to accept 0-9 you can set it's style as "Numeric" in the resource editor.
Shuang. Wu wrote:
when a non-numeric key is pressed a warning dialog will apear
This isn't a good design idea. It would get pretty annoying having to close a dialog everytime you press an incorrect key. Setting the edit's style as numeric will produce a beep when an invalid key is pressed.
- Aaron
|
|
|
|
|
Yes, your suggestion sounds much better; and Thanks very much.
Hello World
|
|
|
|
|
monrobot13 wrote:
Shuang. Wu wrote:
when a non-numeric key is pressed a warning dialog will apear
This isn't a good design idea. It would get pretty annoying having to close a dialog everytime you press an incorrect key. Setting the edit's style as numeric will produce a beep when an invalid key is pressed.
BTW, i failed to do as my previous idea. I would like to know if there is some way to do it?
Hello World
|
|
|
|
|
You can do this using CWnd::SubclassDlgItem
Derive your own class say CMyEdit from CEdit and
add a WM_CHAR handler:
void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
if (nChar >= '0' && nChar <= '9') {
CEdit::OnChar(nChar, nRepCnt, nFlags);
return;
} else {
AfxMessageBox("Invalid Key");
}
}
In your Dialog class add this to OnInitDialog:
m_myEdit.SubclassDlgItem(IDC_EDIT1, this);
where m_myEdit is a Dialog member of type CMyEdit
and IDC_EDIT1 is the edit control id.
Hope this helps!
|
|
|
|
|
Mahendra_786 wrote:
In your Dialog class add this to OnInitDialog:
m_myEdit.SubclassDlgItem(IDC_EDIT1, this);
This is highly unnecessary, and is handled automatically when a member variable is mapped to a control (using ClassWizard).
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
That is HIGHLY correct and
my way in fact may be insufficient not just unnecessary. In fact
DDX_* somewhere calls SubclassWindow to do this.
Moreover the way I suggested I am not sure how
UpdateData will work beside other side-effects.
Due Regards
Mahendra
|
|
|
|
|
Hello guys and girls
I was wondering if it's possible to programatically adjust the privileges of an application, running on let's say 2K/XP, so it can perform actions like installations and other restricted operations when the app is running at accounts without proper permissions. Is that possible at all?
Any information is appreciated.
Thanks in advance
|
|
|
|
|
Maybe it it were running as a service.
Kuphryn
|
|
|
|
|
Deian wrote:
I was wondering if it's possible to programatically adjust the privileges of an application...
Check out OpenProcessToken() and AdjustTokenPrivileges() .
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I use the following code to enable "all" privileges, but still, after enabling them, I can't perform uninstall programatically What am I doing wrong?
DWORD dwLen;<br />
BOOL bRes = FALSE;<br />
HANDLE hToken; <br />
if (!OpenProcessToken(GetCurrentProcess(), <br />
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) <br />
{ <br />
AfxMessageBox("no waaay!");<br />
} <br />
<br />
bRes = GetTokenInformation(<br />
hToken, <br />
TokenPrivileges, <br />
NULL, <br />
0,<br />
&dwLen<br />
); <br />
<br />
BYTE* pBuffer = new BYTE[dwLen];<br />
if(pBuffer == NULL)<br />
{<br />
CloseHandle(hToken);<br />
AfxMessageBox("no memory");<br />
} <br />
<br />
bRes = GetTokenInformation(<br />
hToken, <br />
TokenPrivileges, <br />
pBuffer, <br />
dwLen, <br />
&dwLen<br />
);<br />
<br />
if (!bRes)<br />
{<br />
CloseHandle(hToken);<br />
delete [] pBuffer;<br />
AfxMessageBox("Access denied");<br />
} <br />
<br />
TOKEN_PRIVILEGES* pPrivs = (TOKEN_PRIVILEGES*)pBuffer;<br />
for (DWORD i = 0; i < pPrivs->PrivilegeCount; i++)<br />
{<br />
pPrivs->Privileges[i].Attributes |= SE_PRIVILEGE_ENABLED;<br />
} <br />
bRes = AdjustTokenPrivileges(<br />
hToken, <br />
FALSE, <br />
pPrivs, <br />
0, NULL, NULL<br />
);<br />
<br />
delete [] pBuffer;<br />
CloseHandle(hToken); <br />
<br />
if (!bRes)<br />
AfxMessageBox("Access denied");<br />
else<br />
AfxMessageBox("success");
|
|
|
|
|
What is the return value of AdjustTokenPrivileges() ?
Deian wrote:
...but still, after enabling them, I can't perform uninstall programatically
What problems are you seeing?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Well, the return from the above code is "success". After that if I call GetLastError(), I get "Operation completed successfully". This means that all privileges are enabled, but still, when I try to programatically uninstall any aplication, I get an error, that the app is installed by user with administrative privileges and I can't uninstall such apps . I'm trying to perform this uninstall under restricted "Guest" account. I'm sure that there is a workaround for that though
|
|
|
|
|
Deian wrote:
when I try to programatically uninstall any aplication, I get an error
How are you doing this, and what is the error?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
I'm executing the "UninstallString" value from the registry for any application, and it works perfectly - if it's let's say done under privileged account, the error is "A user with administrative privileges has installed this application, you can not uninstall it" or something similar. I get this error *ONLY* under restricted accounts under 2K/XP. It deals with system policy I guess, but I need a workaround so I can perform these "forbidden" actions.
Thanks for the attention and time spent Mr. Crow
|
|
|
|
|
I'm trying to read a file (which could be using ANSI or MBCS/UNICODE encoding) using the fgetws function, but am having problems. Here's my code:
FILE *file = fopen(tmp,"r");<br />
wchar_t *line = new wchar_t[2001];<br />
wcscpy(line,L"");<br />
wchar_t buf[501];<br />
while(fgetws(buf,500,file) != NULL)<br />
wcscat(line,buf);<br />
The problem is that only the first fgetws function call seems to work correctly; all the following calls return semi-invalid strings, almost double-UNICODE encoded: if there are, say, three spaces, they are stored as 00 00 00 32 00 00 00 32 00 00 00 32 in memory! I'm completely new to UNICODE programming, so I certainly could be making a simple mistake; I just haven't been able to find it yet
|
|
|
|
|
If opened in Text mode (the default), the MS C run-time treats the file as if it is ANSI (i.e. encoded using your default locale's character set). fgetws passes the data read through MultiByteToWideChar to get a UTF-16 string.
If the file is already UTF-16, you'll get the wrong answer (what you're seeing here).
Files opened in Binary mode (by adding a 'b' to the mode parameter) are treated as-is, with no conversions. This also means that CR+LF pairs are not converted to line feeds alone: you'll see \r as well as \n.
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
Ok, thanks for the help! So I'll just try reading the file as binary, and see how that works.
Is using fgetws the best way to fill a char array with the contents of a file, in a straight-Win32 app?
|
|
|
|
|
I have a dialog resource IDD_FORM_XXX in a project. I want to use this resource in another project. Can I copy the dialog resource into the other project?? I cant figure out how to do it...or how to import it.
Thanks.
Jerry
|
|
|
|
|
If nothing else you could copy the dialog from the resource (.rc) file and paste it into the new project.
- Aaron
|
|
|
|
|
I tried that. I dont know why but that will not work.
Jerry
|
|
|
|
|
Make sure you paste it in the dialog section of the new rc file. You will probably have to modify your resource.h for the IDs too.
"We have done so much in the last 2 years, and it doesn't happen by standing around with your finger in your ear, hoping everyone thinks that that's nice." - Donald Rumsfeld
|
|
|
|
|
open the two .rc (src and dest) file only in the same IDE.
then drag and drop from one window to another, if you hold the ctrl key down a copy will be made, else the resource will be moved.
Regards.
I'll write a suicide note on a hundred dollar bill - Dire Straits
|
|
|
|