Score:1

Ubuntu 22.04 How to run an .exe file by the Desktop shortcut

th flag

After updating Ubuntu to 22.04, PlayOnLinux does NOT work to install nor to run any Windows apps, so I had to research and I found the wine command that is a great alternative not only to run any app but also to install just typing in Terminal:

$ wine setup.exe.

After the installation following the steps from this website without installing about winehq because of this, I have to type the following commands every time when I want to play, it's very tiring:

$ cd /home/<user>/.wine/drive_c/Program\ Files\ \(x86\)/<folder_of_app>

$ wine <file>.exe

So I have one idea to make a desktop shortcut with the commands that runs automatically after I clicked it by a mouse.

Could anyone help me?

C.S.Cameron avatar
cn flag
Install VirtualBox, install Windows in VirtualBox. You can then create a desktop icon for that virtual machine.
luisito_36 avatar
th flag
@C.S.Cameron Making a desktop shortcut with VirtualBox is more complex than making two simple files of `.sh` and `.desktop` as the explanation in my answer.
C.S.Cameron avatar
cn flag
One method will run AutoCAD and Solid Works and the other won't.
Score:-2
th flag

UPDATED 4 NOV 2022: Lately, I figured out how to make a Desktop Shortcut to run an .exe file depending on what kind of applications for Windows, for example:

  • If a simple app like notepad.exe, ultraiso.exe or other apps that runs with a simple window without a full screen, it needs only one .desktop file to run: Follow the point A and C.
  • If an app that runs with a full screen like "Need For Speed High Stakes" or "Age of Empires II HD", it needs two files with the different extensions .sh and .desktop to run: Follow the point B and C.

A. Make a new Desktop shortcut archive with the .desktop extension in the Desktop directory /home/<user>/Desktop/, and also in "all applications" directory /usr/share/applications/, copy/paste the following text in it:

  • Note: Between the quotation marks next to wine, it needs double backslash \\ to separate directories of a path.
[Desktop Entry]
Name=<name>
Comment=<comment>
Keywords=<word1>;<word2>;<word3>
Exec=wine "C:\\Program Files (x86)\\<app_folder>\\<file>.exe"
Terminal=false
Type=Application
StartupNotify=true
Icon=<icon>
  • If you want to execute any wine configuration like winecfg, then copy/paste this Exec syntax instead:

Exec=wine <configuration> %f

CONFIGURATION       DESCRIPTION

winecfg             Wine configuration
control             Wine Control Panel
control joy.cpl     Game Controllers
regedit             Registry Editor
uninstaller         Add/Remove Programs

B.1. Make a new shell script archive with the .sh extension in the main folder of the application installed, copy/paste the following shell script text in it:

gnome-terminal --tab --title="<name>" --command="bash -c 'cd /home/<user>/.wine/drive_c/Program\ Files\ \(x86\)/<app_folder>; wine <file>.exe'"

The meaning of each one of shell script:

SYNTAX              DESCRIPTION

gnome-terminal      Open up a gnome-terminal

--tab               Open up a unique tab

--title="<name>"    Name (whatever you want) of a tab

--command="bash -c '<cmd1>;<cmd2>;<cmd3>'"
                    The (bash -c) syntax is a bash command that runs the first
                    <command>, once it is finised, it runs the next <command>
                    and so on.

B.2. Make a new Desktop shortcut archive with the .desktop extension in the Desktop directory /home/<user>/Desktop/, and also in "all applications" directory /usr/share/applications/, copy/paste the following text in it:

[Desktop Entry]
Name=<name>
Comment=<comment>
Keywords=<word1>;<word2>;<word3>
Exec=/home/<user>/.wine/drive_c/Program\ Files\ \(x86\)/<app_folder>/<file>.sh
Terminal=false
Type=Application
StartupNotify=true
Icon=<icon>
  • Note: If Terminal launched by a .sh file does NOT run an app in several seconds, to solve the problem is to press CTRL+C to stop Terminal and it closes automatically. And then, try again the same way to run an app. WARNING ! Never, ever close Terminal by user, it could kill Terminal and it will NOT work FOREVER until the user has to format the hard disk and reinstall Ubuntu.

C. Set the .desktop archive to be executable and allowed to launch, also set the .sh archive to be executable:

  • Note: If the Desktop shortcut or the Desktop directory is set to be writeable for OTHER users, the Desktop shortcut could be blocked to launch.

Setting a file/folder to be executable for USER (owner), is to type u+x; Removing a file/folder to be writeable for OTHER, is to type o-w; This is an example of the command in Terminal to set or remove executable or writeable:

$ chmod -v u+x <file/folder>

Setting a <file>.desktop to launch in the Desktop directory:

$ gio set <file>.desktop metadata::trusted true

Check if it's allowed to launch:

$ gio info <file>.desktop | grep metadata::trusted

D. About getting the icon file to the Desktop shortcut, there are two kinds to choose:

  • The code of the icon (The code of every different icon is in every file in /usr/share/applications): Icon=<code_of_icon>
  • Getting from any file of PNG: Icon=/<path>/<file>.png

That's all, best regard.

Satoshi Nakamoto avatar
lc flag
I'm pretty much sure you messed up in your "script theory". I've seem many direct executable files in Linux and no you don't need two files to do the task of one! Try to set "arguments" to your command line, if it's no there, try to set the whole command in that shortcut. A pretty common task in programming daily skills is to "set arguments to your command lines"
Sad3ng avatar
vn flag
i think you can run exe on Exec without `cd` nor `sh` script.
luisito_36 avatar
th flag
@SatoshiNakamoto, This is the best and easiest way that I figured out how to and I tested before posting my answer. Furthermore, to click with a mouse, is to any `.desktop` file not a `.sh` file; to open a `.sh` file, you have to open Terminal and type `./file.sh`.
luisito_36 avatar
th flag
@Sad3ng, Linux does NOT run any `.exe` file without the `wine` command, in addition `wine` does NOT work to run `.exe` with a path directory, for example to type in Terminal `wine /home/user/path/file.exe` it doesn't work at all. So you first have to type `cd /home/user/path/` and then `wine file.exe`. On the other hand, how do you run `.exe` without a `.sh` file? How do you add `wine` in the `.desktop` file to run any `.exe` file?
Sad3ng avatar
vn flag
@luisito_36 you can use WINEPREFIX to remember of wine to run .exe path.
luisito_36 avatar
th flag
I just updated my answer, check it out.
Satoshi Nakamoto avatar
lc flag
My last time using `wine` I was able to double click any `.exe` and the file automatically opened like any other windows file and many other `.exe`s I tried worked. In the past that wasn't possible but not today. Just set `wine` as the default program for `.exe` files
luisito_36 avatar
th flag
Lately, I just realized that If an app that runs with a window not full screen like notepad, microsoft word, etc., `wine` can work with a path directory typing in Terminal: `wine /path/file.exe` but if an app that runs with a full screen like *Need For Speed*, the `wine` cannot work with a path directory, so to work it is to type two commands in Terminal: `cd /path/` and then `wine file.exe`
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.