How can I use iTunesLib in unattended mode? - c#

I'm making a little app to automate my iPod update. My purpose is sync my iTunes library with my actual one and reencode songs in a lower quality for the iPod.
I use the Interop "iTunesLib" from iTunes.exe and I'm working on C#.
My program works pretty well but I have a big issue with iTunes. If a modal box is opened by iTunes during the process (could be "error while importing song", or just even "a new update is available" at iTunes startup...), then my app is completely stuck and must wait for the user to close the popup.
This is annoying because I expected to run my app at night and the process of reimporting/reencoding takes a while.
Is there any way to either tell iTunes to not pop any message, or to ask it to close an already opened one?

Maybe try calling the IiTunes.VisualsEnabled method passing in FALSE.
From the iTunes COM SDK:
HRESULT IiTunes::VisualsEnabled ( [in] VARIANT_BOOL shouldEnable )
Set whether visuals should be displayed.
Parameters:
shouldEnable True if visuals should be displayed.
Return values:
S_OK The operation was successful.
E_ACCESSDENIED Visuals cannot be enabled or disabled. For example, this can happen if the iTunes Store is currently being viewed.
E_FAIL An unexpected error occurred.

Well, after having this question open for more than a year, the correct answers seems to be: I can't
However there are several alternative libraries that might be useful.

Related

DirectX End-User Runtimes Redistributable Exit Codes

Can anyone point me to a list of exit codes for the DirectX End-User Runtimes (specifically the June 2010 version, if it matters)? I apologize in advance if this is a simple matter (it should be), but apparently my google skills are sub-par as I have been unable to find them.
For bonus points:
I'm trying to use InstallShield LE to create an installer for a game I am working on. I downloaded the DirectX End-User Redistributable (June 2010). This redistributable has the user install/extract the DX files to a location they specify with the expectation that the user will then manually run the DXSETUP.exe that is extracted to that location. I handle this silently in a custom action with a location that I have specified (with the intent to clean up these files in a later custom action).
From here, I would like to run the DXSETUP.exe from the location that I specified and respond appropriately to any errors that it encounters (display a message to the user that will help them with their specific problem). I'm currently using a C# executable that I have created to run the DXSETUP.exe, which is run from ISLE via a custom action. Since I couldn't find a list of the possible exit codes for DXSETUP.exe, I decided to display a generic message whenever a non-zero (unsuccessful) exit code is encountered which will contain the exit code returned by DXSETUP.exe. Normally, I would call it a day and wait until users start contacting me with error codes, but this setup does not cover a very specific case.
Apparently, if the user cancels the DXSETUP.exe, it returns an exit code of 0, which is supposed to indicate success. I do not know how to detect/deal with this circumstance. As-is, my game's installer will continue to run happily, leaving the user unable to play the game after the installer finishes due to missing DX files.
I apologize if this came out a bit verbose, but hopefully it clearly and adequately explains my situation.
Don't give the user the chance to cancel by running dxsetup.exe with the /silent flag. This is recommended as a best practice by Microsoft.

Detecting raised-event at OS-level (OS Appearance)

I have what seems to be a common problem. I am running Windows 7 Home Premium on one of the most awesomest computers (when it was bought last year) and certain visual effects just automatically turn themselves off.
My average user experience rating is high, so it doesn't explain why this happens. The only feature that ever gets turned off is the 'Show window contents while dragging' option. And it really annoys me.
There are currently no working solutions to this problem online. Other than to "there must be a conflict with another app installed on your machine."
And yes, I do know what app is causing this conflict. It's my bloody Internet Provider's software - you know... that app that you absolutely MUST have open at all times when you're connected to the net.
So, I had a thought. What if I could subscribe to an event so that my app that runs in the background will detect when this 'show window contents while dragging' option is turned off - and then my app will simply turn it back on again.
When I do this manually, it seems to stay in effect for about an hour or two, then it gets switched off again.
Is it possible to handle these types of events, and re-start certain visual effect features? If so, are there any resources on this?
I have not been able to find anything on this sibject yet.
Yes the WM_SETTINGSCHANGE message is sent to all windows when a system setting is changed. Then you can call SystemParametersInfo with SPI_GETDRAGFULLWINDOWS to determine if the "Show window contents while dragging" is disabled and use SPI_SETDRAGFULLWINDOWS to enable it.
So all that you will need to do is create an application with a form (that can even stay hidden) and override the forms WndProc and handle the WM_SETTINGSCHANGE message and call SystemParametersInfo using p/Invoke. The p/Invoke definition for SystemParamtersInfo is available at pinvoke.net
Altough what may be easier is change security on the HKCU\Control Panel\Desktop\DragFullWindows registry value so that it can't be changed.

Block a Processes Child Window?

I am launching a process in C# .NET that for some reason opens a message box when it is initially launched. What I need to do from my application is find some way to either prevent this message box from ever being opened, or basically "click" the OK button on the message box from my code.
The message box is causing the process to hang when we run it as a service, so I now need to find some way to either prevent that box from ever opening or just close it (select OK) from my code.
I have been looking at some Win32 API samples, but I have never had to use it before and it looks a bit strange. Any suggestions would be great!
Edit
Here is a batch file that was supplied as a work around for the issue. However I would much prefer to have it running an executable if possible. The explanation was that using the -supw parameter (to set a password on the server) causes this message box to popup. This batch file is tested and works, but it requires you have a duplicated executable (murmur2.exe) created which is ghetto.
set /p VAR= < superadmin.txt
start murmur2.exe -supw %var%
ping 0.0.0.0 -n 3 > NUL
tskill murmur2
murmur.exe
PostMessage(FindWindow("#32770",*Title of the message box*),WM_CLOSE,NULL,NULL);
Since there might(with a very slim chance) be a same window opened with the same class name with the same title at the same time, this is not a fail proof way. However the alternatives are simply an overkill. If you really want to make it fail proof, you'll have to call EnumWindows to enumerate all top-level windows, then for each window, call GetWindowThreadProcessId and compare the window's process id with your launched process' id. If they are equal, you can then call GetClassName and GetWindowText to compare the class names(always "#32770" for common dialogs) and the title of the message box to verify that you're trying to close the right window. Once it's done, you can call PostMessage with WM_CLOSE using the hWnd that you found.

FindWindow doesn't return IntPtr.Zero, although the window is already closed

I'm trying to control a Java application from my C# program. Before the program begins to input data, it checks if there are any pervious data input windows, and tries to close them.
The code for checking if a window exists is:
public static bool WindowExists(string WindowName)
{
IntPtr hWnd = FindWindow(null, WindowName);
return (hWnd != IntPtr.Zero);
}
Until now, I simply used this method in a while loop (sending Alt+F4 to the windows), until there was no open input window left.
A while ago the Java application got an update, and this method no longer works. For some reason, WindowExists keeps returning true, even after the data input window is closed. This only happens if the input window existed at least once.
I even tried to add Thread.Sleep() to the loop, to make sure this isn't caused by some latency in the Java app, but it didn't work.
Sometimes simply calling WindowExists crashes the input window.
There's no problem with the code, because it has worked before, and it still works with other programs, so it must be a problem with the update in the Java program.
Is there any alternative/more reliable way to check if a window exists?
Changing sending Alt+F4 to "close window event" might also worth a try, but I have no idea how to send this event to another program's window.
I'm a newbie, so please keep the answer simple.
Thanks in advance.
I would use Spy++ to watch the window handle of the Java app, and see if you can figure out what else is going on - I agree there has to be a way to tell that it is closed.
I assume watching the process list is out of the question...
I would hazard a guess that whilst the Java app is running and consequently, the JVM, the 'handle' to the window has not yet been garbaged collected and as such appears to the underlying pointer mechanism as still being valid.
If it was me writing that stuff (and if I was able to change the Java code) I'd probably add a means of querying the java app to see if its windows are showing.
A sockets interface or something.
My guess is that either the window hasn't been completely disposed of by the Java code/VM, or it's handling Alt+F4 in some special way (i.e. maybe making itself invisible rather than closing).
Creation/deletion of windows is out of your control. If you want to reliably detect the presence of 'someone else' using the same resource a you want, have that other party communicate it explicitly.
The other party may signal it's presence by creating a file, opening a port, whatever, and can release/delete/close it on it's exit.
Try to make additional check using IsWindow API, on hWnd value returned by FindWindow.

Call to a method never returns

I am working with a COM component. There is a method that does this call to the component, and this method is used many times in my application, for each document to be processed, this method is called.
One weird thing happens sometimes suddenly, doesn't matter the amount of documents processed, it can happen after processing 60, 100 or 300 documents, or just don't happen. The weird thing: the call to the component doesn't return. The method stays stuck into the call line. Do you know any COM particularity that could be causing this problem?
From your question I get that your are doing COM automation with documents. If your COM object is a document processing application (Would MS Office be the right guess?) then it might be that the application is simply blocked by a popup.
This phenomenon happens quite frequently when you automate e.g. Word or Excel. You should do several things to work around this problem (I'm talking about MS Word here):
disable alerts by setting Application.DisplayAlerts accordingly
install the complete products to avoid Windows Installer popups asking for missing features
implement a time-out mechanism that will kill the application if any modal dialog is requesting user input. The reason for that is that there are certain types of popups which cannot be suppressed (If you need further information please ask).

Categories

Resources