|
Hello! I am following this guide about switching background wallpaper via a windows service http://www.codeproject.com/KB/cs/C__Wallpaper_Switcher.aspx[^] but cant get it right.
My service is up and running (it do other things så of that I am certain) but the background wont just change. If I try exactly the same code in a win form app it works (and SystemParametersInfo returns 1) but not in my service (SystemParametersInfo returns 0). Has Vista something to do with it, security limitations? Is it posible to get better error messages from SystemParametersInfo?
|
|
|
|
|
Don't ask here, it's not our code. Any qiestion regarding an article should be posted on the article. It's really quite a clever idea - you ask the person who wrote it why you're having a problem.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Well then maybe I can change my question a bit? Regardless of the article, how do I change the background image within a windows service? I have search the web for hours now and all code are variations of the code as shown in the article (pretty much c# to me and this is a c# forum, right?)...
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern Int32 SystemParametersInfo(UInt32 uiAction, UInt32 uiParam, String pvParam, UInt32 fWinIni);
private static UInt32 SPI_SETDESKWALLPAPER = 20;
private static UInt32 SPIF_UPDATEINIFILE = 0x1;
/.../
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, @"C:\...\test.bmp", SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
Works perfectly in win forms in vista but not in my service of some reason.
|
|
|
|
|
It's a service. You shouldn't be able to access the UI from a service.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
It won't work in a service because the service is running under a different account and Desktop. You're actually changing the wallpaper for a desktop that you cannot see.
This should not be done from a service at all. This should be a user app launched from the Run key in the registry. Wallpaper setting a user specific, not machine specific. This means that every user can have their own wallpaper, without affecting other users.
|
|
|
|
|
Ok, thanks. I did find a "half workaround". It is possible to change the wallpaper registry key with the standard service account. Not directly in HKEY_CURRENT_USER but in HKEY_USER. And hkey_current_user is in fact only a copy of one of thoose in the hkey_users, just find the right one (the one with write permissions is the same as hkey_current_user so just loop them through an try them out...)
Changing the wallpaper key only applies when the computer is restarted, but it was quite fun anyway. The image has to be find locally but if removed, I made my service download the correct image aswell...
RegistryKey Keys = Registry.Users;
foreach (string Keyname in Keys.GetSubKeyNames())
{
try
{
RegistryKey Key = Registry.Users.OpenSubKey(Keyname.ToString() + "\\Control Panel\\Desktop", true);
Key.SetValue("WallPaper", "C:\\Users\\" + UsersDir + "\\Desktop\\funny.jpg", RegistryValueKind.String);
}
catch { }
}
Not very serious project maybe but I've learned alot on the way.
|
|
|
|
|
CURRENT_USER is a pointer to the correct user hive under USERS, not a copy of it.
maxald wrote: just find the right one (the one with write permissions is the same as hkey_current_user so just loop them through an try them out...)
This is wrong. Services run, by default, as the Local System account, not a user account. They also don't normally have any idea anyone is logged in, if at all. The fact that the service found A user have that it could write to is mearly a coinicedence. It did not find THE known user account, unless you've written code to try and figure out which user that is.
|
|
|
|
|
Thanks for clearing things out, I'm all new to programming so I really appreciate that!
I find one other thing on this subject... when looping trough all user folders in c:\Users within my service, it has write permissions only in the logged in user folder. Is this a coinicedence aswell or could this be part of a solution finding who is the logged in user?
|
|
|
|
|
It's the exact same situation. It cannot be relied upon to determine who is logged in, if anyone. Also, since XP/Vista/7 can have multiple people logged in at the same time, who's the one at the console?? There's no way to tell. Also, it's not just a user account that's logged in. There are also built-in accounts that are being used, such as Local System, Network Service, Local Service, ... Are you going to needlessly attempt to change those accounts too??
That's why I said the best place to use this would be a user app launched out of the Registry's Run key, not a service. That way, the app runs as the user, only when a user is logged in, and doesn't have to worry about figuring out who's logged in.
|
|
|
|
|
hi friends,
i downloaded inpout32.dll file and included to my resource file.
i get the following error
'C:\WINDOWS\INPOUT32.DLL' is not a valid Win32 resource file
wat should i do now?
cheers,
priya
|
|
|
|
|
Have you Googled it?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
hi friend
I'm new to programming i don no how to do it
|
|
|
|
|
he meant Google
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Well, I would start by getting a good book on the programming language you are trying to learn. Importing and using DLLs is not exactly a step after Hello World.
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
I suppose by "importing a dll file" you mean that you want to use that Dll in your application. In order to do that you need to reference the Dll in your build (if the Dll is a .NET Dll) or you need to load specific functions from the Dll via P/Invoke (if it is a native - that is non .NET Dll).
Either way I suggest you look for a Dll tutorial if you are new to this.
You should be able to find information on Codeproject searching for P/Invoke (short for Platform Invoke) or looking for some basic C# tutorials which probably also explain usage of Dlls.
|
|
|
|
|
Hi All,
I have .Prn file which was generated out of PCL printer.I need to find a string in that file and then I have to replace it with another string.
Iam able to do it by using stream writer,streamreader,Binary reader,binary writer and file streams.
But if gave a print(LPR)for it, it get failed and giving me syntax error as Illegal tag.
If I print original file it is printing very well.
I came to know that while writing it has lost some of its originality ,so it was failed
Please help me
Thanks in advance
|
|
|
|
|
balu12345 wrote: I have to replace it with another string.
Thats probably whats wrong then. Either the value you are replacing with is illegal OR you are replacing something you didn't mean to. Why not save both the original and your new version to disk and compare them - there are loads of free utilities to compare files.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Hi,
Thanks for the reply,
The original file size is like 16k, after the editing it becoming as 22k..
more over it is not normal file,It is a file generated by PCL printer.
So may be during the conversion it is losing printer supported font.
so that's the reason printer cannot understand the file(after editing)to print.so it gives syntax error as Kernel and Illegal tag error.
I even cannot compare both file because the file is generated by PCL printer which has some non-readable data
I have no clues to overcome this problem
kindly help me
|
|
|
|
|
balu12345 wrote:
The original file size is like 16k, after the editing it becoming as 22k..
So basically what you are doing has corrupted it.
balu12345 wrote: it is not normal file,It is a file generated by PCL printer.
Yes, so unless you know the format of the file you will mess it up.
balu12345 wrote: I even cannot compare both file because the file is generated by PCL printer which has some non-readable data
Ther eis no such thing as unreadable data. Use a hex editor to compare, there are plenty freely avalable.
It does beg the question though, why do you have to change the PCL file rather than the original data.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
HI,
i have a strange problem:
i have a datagrid view bound to a table.
when i edit a cell content i press a button to save this changes like this :
TA_Users.Update(dS_StationManager.T_Users);
dS_StationManager.T_Users.AcceptChanges();
THIS WORKS FINE.
now i've decieded to removw the button so that the changes will be saved without the user pressing the button.
i've tryied copying this two code lines
TA_Users.Update(dS_StationManager.T_Users);
dS_StationManager.T_Users.AcceptChanges();
to diff datagridview events like :
1. dgvUsers_Edit_CellValueChanged
2. dgvUsers_Edit_CellEndEdit
but nothing happens, the database does'nt change
Help Req
THANKS
Have Fun
Never forget it
|
|
|
|
|
Are those events actually tied to the delegate?
The best way to accelerate a Macintosh is at 9.8m/sec² - Marcus Dolengo
|
|
|
|
|
they occuer ( i debuged this )
if that waht u mean
Have Fun
Never forget it
|
|
|
|
|
copy back to button and check if its still working
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Xmen wrote: copy back to button and check if its still working
what do u mean??
call the button callback form the event??
Have Fun
Never forget it
|
|
|
|
|
I mean copy paste that code in a button and test that is it still working. It may possible that you change something and forgot...
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|