C# Is there any other way of opening web shortcuts - c#

Im currently using
System.Diagnostics.Process.Start(link);
to open web links on a dropdown menu in a program for work. However, the security suite on the works computers do not allow this to function. I have spoken with IT and they will not relax the security policies on this.
I've had a search and most of the posts suggest the way I have already done it.
We use IE in work.
Is there another way of opening links?
Thanks

You can launch IE directly from Process start with a url as a parameter like:
System.Diagnostics.Process.Start(#"C:\Program Files\Internet Explorer\iexplore.exe", "http://www.stackoverflow.com");
Cheers,
CEC
PS: additional possible solution: BRIBE THE IT DEPARTMENT, good food is often a working solution to IT dept. problems.

Can you use an embedded browser window? If so, embed the browser window into your C# application and open the link in that window. If not, the starting of the process may not help you because the security suite may prevent this as well.

Have you tried using a ProcessStartInfo object with the UseShellExecute property set to false? This may have a chance of circumventing the security restriction.
http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.useshellexecute.aspx

Related

How to add extension to running remote multilogin webdriver? (Selenium C#)

First I tried to add extension directly from chrome webstore, but problem is alert popup which appears after you click "add to chrome" is not reachable by selenium. After I wanted to try using options.AddExtension, but multilogin profile starts before selenium takes control so this method is useless. I know that I can manually import .crx for every profile but there are thousands of profiles and I need to automate process of installing extensions. I don't know what to do, I heared there's option to reach popup alert in chrome webstore but can't find it. Or maybe there are other ways to install extension after browser started? I'm glad for any help or advice
I have 2 possible scenarios for you, hope that works out since I don't have direct access to this specific need you have because the extensions may differ.
Not using Selenium, you gonna start the chrome process using the class Process and add the flag --load-extension= to load the specific profile/extension that you need. You can see the entire comma here. To sum, you can use this snippet below to load:
chrome --user-data-dir=/tmp/someuniquedirname --load-extension=path/to/extension --no-first-run //Note: some flags may change between versions of chrome, see full documentation
After defining the extension and start chrome, you can now get hold of the process with Selenium by using another flag: --remote-debugging-port=http://localhost:[localporthere]. After that, start the process than tell to Selenium to get hold of that process with the port and do your job.
Another way is to start the process installing the extension manually and in another Thread use some Automation UI (Teststack.White or FlaUI) to click on the popup you have. I can't extend here in the entire code for this solution because it will go to a opinion-based answer, but you can check on FlaUI for that use, and follow that path:
Selenium starts the program, click on the install extension and wait for the popup to show-up;
New Thread;
FlaUI gets hold of the process that you already start;
Using UIElements, click on the "ok" button you need;
FlaUI drops;
Back to the main thread.
If you need any clarifications about the solutions above, just comment and I'll try to help you further.

Custom icon that opens URL

I've only used Visual Studio a handful of times.
Can I make an executable with a custom icon that strictly opens a URL in a web browser?
I am assuming Visual Studio will be the best tool to help me achieve this, although I am open to better options.
It has to have a custom icon and be a stand alone file.
Thanks.
if you don't need it to be an executable you could quickly create a windows shortcut.
http://support.microsoft.com/kb/140443
You can personalize the icon too.
As PrashantGupta has pointed out you can only use a subsets of windows icons if you want it to be a single file.
Sure,
Just write a single line console app with this as your code
System.Diagnostics.Process.Start("http://my.url.com");
You can configure an icon from within visual studio easily too.
Sure, did I get this right: You need an EXE with custom icon and launches a URL?
If you choose C# as your development language the following code will achieve what you want:
namespace URLLauncher
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Process.Start("http://www.google.com/");
}
}
}
Changing the icon is also quite straightforward in visual studio as well. See this: Adding an icon to my finished application
Also try not to make your application a "Console" application as that will pop up a "black console window" when you launch the app if you need a double-click interface from the user (which I infer from your wanting an ICON).
Hope this helps.
If you decide to go the C++ route, passing a URL to the ShellExecute function will let you launch a website using the user's preferred browser.
See http://support.microsoft.com/kb/224816
And you don't really need anything from the C or C++ runtime for this, so compile with /NODEFAULTLIB use the /ENTRYPOINT linker option to skip all that, make your executable truly tiny, and have very few dependencies (meaning none that aren't included in every version of Windows since 95). It'll start faster too, not needing to run .NET or any library initialization code.
Add your icon in the usual way using the Resource Compiler.
Solves the problem, not necessarily with the requested tool
While we are at-it, so to speak, I thought someone must have invented this wheel before, so if you are not interested in any development what-so-ever (check licenses before use tho), here are some online tools to do what you want:
Web shortcut producer
Remember to scan the EXE for for malware. Hope it helps :-)
The Visual Studio route has a lot of advantages and will work for this situation. Although, it is overkill for the project I am working on.
I have chosen to go with this solution:
Build a .bat file with the command:
start http://www.google.com
Then use a bat to exe converter which allows icon assignment.
Worked like a charm and quick.

write code to find the opening windows on desktop

Is there anyway to find what kind of window is opened on the desktop in real time?
It may need C# or C++. What I have found right now is to use C# Process.GetProcesses() method to find the opened windows on desktop.
But the output cannot be changed when the users have opened any new windows. So, is there any method I can use to track the opening windows in real time?
Also, is there any way to track the mouse movement on a specific window by using our web service?
Many many thanks!
I do agree with tnw that this sounds sketchy (possibly an example would be useful to help here). However, you want to look at the windows api calls:
GetForeGroundWindow
GetCursorPos
The first will only give you the current window, and not all open windows, but it sounds like this is what you really want anyway?
Source code to Windows keystroke logger that does this (in C++): http://16s.us/16k/
Edit: It shows the open window the user is typing in (in real time), but not all open Windows, only the active window in use.

Is there a way to open Windows date and time settings dialog from a WinForms application?

I'm working on an embedded software, where we would like to avoid exposing Windows features and interfaces as much as possible. However, users need the ability to change the system date and time, and perhaps also timezone or daylight saving mode.
I thought I would create our own simple Form for that and I tried digging into Win32 API calls, but realized that it's not a simple way.
So I found that basically the easiest way here would be to invoke the well-known Windows dialog from the software and let users changing stuff there. I couldn't find anything about it so far. Is there any executable for it (such as gpedit.msc for example), or is there any API calls to show that window? If not, or in case of any contras which I didn't take into count, can anyone suggest a better way for this task?
EDIT: Thank you for the timedate.cpl tip, I will try it as soon as I can.
On my desktop version of Windows you can show that dialog by executing timedate.cpl. I've no idea whether or not that will work on your embedded Windows.
Yes there is. Use this code and upon button clicking it will work:
System.Diagnostics.Process.Start("timedate.cpl");
It should work. If you want to open other windows controls you only have to change "timedata.cpl" to the command of your choice.
Good Luck!
Try this:
Process.Start(System.Environment.SystemDirectory + #"\TimeDate.cpl");
But I don't know if it works on your embedded Windows...

How do I kill a particular chrome tab/process

I am writing a windows service that I would like to run as a scheduled task.
On Start I want it to read in the chrome processes and kill any that have a particular url..
I can get the processes using
var list = Process.GetProcessesByName("chrome");
but after that I am stumped..
The MainWindowTitle of each process is "" and the MainWindowHandle is 0 so doesn't help me.
I have read numerous posts related to this and it seems there is no api into chrome so am I wasting my time?
Any help appreciated
J
If you look at spy++ you can see that you can find root windows that do have their Caption set to the html page title. Also a child window is the url bar so if you enum the child windows of all the chrome windows you uld be able to find it.
sho
While it is possible to do this, I wouldn't recommend it. Injecting yourself in to other processes and reading their contents can cause unpleasant behavior and is hard to get completely correct, but if I was going to try this, I would use the UI automation tools provided by MS (http://msdn.microsoft.com/en-us/library/ms747327.aspx), or White (http://teststack.github.io/White/). Those are going to be the best bets.

Categories

Resources