|
Oops!
|
|
|
|
|
Are you looking for an empty disk sector? On what type of file system?
Best Wishes,
-David Delaune
|
|
|
|
|
Hello all ,
As windows Vista and windows 2008 have all come with an option of "Run as Administrator", Is there some way to programmatically invoke some executable so as it could be invoked as 'Administrator' ?
Regards,
Kushagra
|
|
|
|
|
|
Randor wrote: support article:
CreateProcessAsUser() windowstations and desktops[^]
P.S.
Have you finally decided to follow my recommendations[^] for delaying the windows shutdown?
Hey Randor,
Its gr8 to hear from u again, CreateProcessAsUser is what I am looking into, but what I need is some way to elevate permissions of my executable as soon as it is invoked.
and yes I was successful in delaying shutdown by creating a service and handling SERVICE_CONTROL_SHUTDOWN . Your suggestion helped me a lot . Thanks for always showing the way.
Kushagra
|
|
|
|
|
Hi Kushagra,
I should have given a more complete answer. I assumed that you were still working on that windows service. The following MSDN article addresses elevation from a standard windows application.
Redesign for UAC Compatibility (UAC)[^]
Best Wishes,
-David Delaune
|
|
|
|
|
Thank you
I am now looking at it
|
|
|
|
|
Can I include some thing in my code to make the application run as Administrator every time when it starts ?
Or could I make any other application which when invoked starts my executable to runas Administrator ???All this I have to do in VISTA and WINDOWS 2008 as UAC always comes into picture ..
Kushagra
|
|
|
|
|
Hi,
I am trying to send a pdf file from server to client using sockets. My code is
server:
FILE *fp;
int i,j,endoffile;
char buf[1024],pathoffile[1024],msg[24];
if((send(TheClient,msg,sizeof(msg),0))!=0)
if((recv(TheClient,pathoffile,sizeof(pathoffile),0))!=0)
printf("\n\tPath is %s",pathoffile);
fp=fopen(pathoffile,"rb");
if(fp==NULL)
{
printf("\n\tFailed to open File");
system("pause");
}
for (i=0, endoffile=0 ; ; )
{
j = fread(buf, 1, sizeof(buf), fp);
if (j < 0)
{
system("pause");
}
if (j == 0)
{
endoffile = 1;
printf("\n\tFile successfully sent");
system("pause");
}
j = send(TheClient, buf, j, 0);
printf("\n\tsending buf to client.Value of send %d",j);
if (j <= 0)
{
printf("\n\tUnable to send");
system("pause");
}
}
}
client:
int i,j;
HANDLE hFile=NULL;
char buf[1024],msg[24],pathoffile[1024];
DWORD dw;
if((recv(sock,msg,sizeof(msg),0))!=0)
printf("\n\t%s",msg);
gets(pathoffile);
if((send(sock,pathoffile,sizeof(pathoffile),0))!=0)
printf("path sent sucessfully");
hFile = CreateFileA(".", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == NULL || hFile == INVALID_HANDLE_VALUE)
{
hFile = NULL;
}
for (i=0 ; ; )
{
j=recv(sock, buf, sizeof(buf), 0);
printf("\n\treceiving file...plz wait.");
if (j <= 0)
break;
i += j;
WriteFile(hFile, buf, j, &dw, 0);
}
CloseHandle(hFile);
when i run my program .in server window it shows "sending buf to client.Value of send 0".I am unable to that where is the error happaning?
|
|
|
|
|
After the following line:
j = send(TheClient, buf, j, 0);
you should check for SOCKET_ERROR and WSAGetLastError() to see if there was a failure.
Also in your client code you have hFile = CreateFileA(".", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL, NULL); which is wrong. You cannot create a file with the name ".".
I would suggest adding some more error checking code to both systems to try and discover what is happening.
|
|
|
|
|
Embarrassing as this code may be to me (I am a bit of a C++ noob), why don't the third console input take? It acts like I held down the enter key after entering my height in inches.
This sample is part of an exercise from a book.
#include <iostream>
using namespace std;
const unsigned char inchesInFoot = 12;
const float metersInInch = 0.0254;
const float poundsInKilogram = 2.2;
int main()
{
unsigned char userFeet, userInches;
unsigned short userPounds;
float userMeters;
float userKilograms;
cout << "Enter your height in feet:";
cin >> userFeet;
cout << "Now enter the remaining inches of your height:";
cin >> userInches;
cout << "How many pounds do you weight?:";
cin >> userPounds;
userInches = userFeet * inchesInFoot + userInches;
userMeters = userInches * metersInInch;
userKilograms = userPounds / poundsInKilogram;
cout << "Your BMI is " << userKilograms / (userMeters * userMeters) << endl;
return 0;
}
|
|
|
|
|
I don't see anything wrong with it, and it works for me.
Squirrelly keyboard, maybe?
|
|
|
|
|
LunaticFringe wrote: I don't see anything wrong with it, and it works for me.
Its only when I enter 11 in the inches part that it skips the weight cin .
|
|
|
|
|
You have problems in the data types. char is not appropriate here. Everything will work fine if you change that.
Best wishes,
Navaneeth
|
|
|
|
|
N a v a n e e t h wrote: You have problems in the data types. char is not appropriate here. Everything will work fine if you change that.
Yes, that fixed it. I wish there were a simple unsigned byte primitive that would work in this context.
|
|
|
|
|
Ah! That's it - it's a two-character sequence, and you're streaming into single character variables. It imagine what's happening is the second character is buffered and then read as the third input. Try it with just single character entries and I bet it'll work.
|
|
|
|
|
Yeah, I changed char to short and it worked. I wish there were a simple byte primitive like C# has.
|
|
|
|
|
Well, there is, and char is (god, I'm rusty on stuff like this) typedef'd to a byte - it IS a byte. And that was the trouble - the variables only allowed for one byte of storage, so it stuck one byte into each, not realizing you'd intended to enter a multi-byte response into a single variable.
Your fix is appropriate, methinks - the variables probably should have been shorts or ints to begin with.
|
|
|
|
|
There is an __int8 primitive in VC++, its just not standard C++. cin handles it the same way as it does with char. There should be a way to enter a value of up to 255 in the console window and have it convert that string into its byte representation like .NET's Byte.Parse("255");
|
|
|
|
|
I wouldn't be surprised if there's a way to do it; someone else might know how. I'm afraid I'm recovering from years of losing brain cells to Java. Totally ruins ones C++ skills, it does.
|
|
|
|
|
Hi Captain,
There is absolutely nothing C# can do that C++ cannot do. Your sample code is flawed. You are trying to put multiple bytes into a 1 byte container.
CaptainSeeSharp wrote: There should be a way to enter a value of up to 255 in the console window and have it convert that string into its byte representation like .NET's Byte.Parse("255");
Like this?
string magic_SeeSharpBuffer;
cout << "Enter a byte:";
cin >> magic_SeeSharpBuffer;
BYTE b = atoi(magic_SeeSharpBuffer.c_str());
The design and theory of C# and .NET languages somewhat has roots in OLE/COM technologies. Your C# datatypes are similar to VARIANTS[^] where the datatype can be interchanged. The .NET languages discourage direct memory access and direct data conversions by the end-user. The .NET internel conversion code was written by an engineer at Microsoft and you rely on the IL instructions generated by him/her.
The C++ language gives the engineer more control over the datatype and memory. The C++ language trusts that you know what you are doing. It will allow you to write code that will blow-up and crash.
The Microsoft C++ compiler *could* detect these situations and throw a compile-time warning or error. But believe it or not sometimes C++ software developers *want* to overflow a buffer or overwrite memory. Thats exactly what makes the language so powerful. Its greatest strength and at the same time its weakness.
I am happy that you are experimenting with the C++ language. Don't get frustrated because eventually you will understand these fundemental concepts and will be a better software engineer because of it.
Best Wishes,
-David Delaune
|
|
|
|
|
Hey, this is my first time posting anything on this forum. I need some help with this reoccurring problem. When I try to typecast a character pointer to a LPCSTR for some reason all of the string doesn't make it. When I try to pass it to a function that uses a LPCSTR it gets clipped at the whitespace. So if I use something like "This is a test." the only thing that seems to make it to the function is "This". I've noticed this with MessageBox and the send winsock function. So I guess it may be a const char* to char* problem but anyway the point is I have no clue whats going on and this has been bugging me. Below I left some code I was messing with. This is probably something simple that I'm missing but any help would be gratefully appreciated.
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
char MyString[255];
scanf("%s",MyString);
MessageBox(NULL,LPCSTR(MyString),"Test",MB_OK | MB_ICONINFORMATION);
return 0;
}
|
|
|
|
|
From Format Specification Fields: scanf and wscanf Functions[^] :
An input field is defined as all characters up to the first white-space character (space, tab, or newline), or up to the first character that cannot be converted according to the format specification, or until the field width (if specified) is reached. If there are too many arguments for the given specifications, the extra arguments are evaluated but ignored.
Setting a breakpoint on the MessageBox call would allow you to examine the contents of MyString before it's displayed, where you can see it's already truncated.
A couple additional points. My C is a little rusty, but ..
a) Your 'LPCSTR(MyString)' cast is unnecessary.
b) It's not a cast, but rather (I believe) an invocation of a LPCSTR constructor with MyString as a parameter. You're not executing a cast, you're creating a new null-terminated string pointer, pointed at MyString.
c) A cast would have been '(LPCSTR)MyString'. But like I said, it isn't required here.
modified on Saturday, October 31, 2009 12:52 AM
|
|
|
|
|
Oh ok I see what your saying. I find it kinda hard to believe I missed that in all the time I have spent using C++ Thanks for the help and explanation.
|
|
|
|
|
It's definitely incorrect syntax for a cast, and a cast was definitely unnecessary; my only doubt is whether or not it executes a constructor the way you'd written it. Like I said, I'm a bit rusty.
|
|
|
|
|