-1

I have a program which has a unique user id that only belongs to that user. that id is hard coded and used in a web interface where the user can be shown his computer and not someone else's, so whenever i need to give my program to another user i need to recompile the executable with the new hardcoded executable. so i want to make a simple form that has a textbox for the client id and a compile button, so it compiles an executable with the client id in the textbox hard coded in that executable. How would i go about doing this? I researched this and found this but i don't think it can be used in my situation.

My program is used to control your pc with a web interface so lets say i got 1 user on my website that has 2 computers. He would need an executable made for him with his user id that is in the database of my website. But what if i got another user and many more, i need to make thousands of versions of my program.

Also as a side question can this be done on a website let's say i have users on my website and every user has his unique id and i want that id to be hardcoded in my program when they go to download it. please don't focus on this too much as its just a side question.

DavidAnastasov
  • 63
  • 1
  • 10
  • 3
    Sounds x/y ish. why dont you just use commandline arguments, the mac address, a web service login, or any number of things. – TheGeneral May 21 '18 at 08:39
  • 4
    Why You don't include it in a configuration File, and the user have both the exe and the config ? – Hany Habib May 21 '18 at 08:39
  • *Unique client id that only belongs to that computer.* FYI If your using this as some kind of security mechanism it would be trivial to circumvent – Liam May 21 '18 at 08:40
  • 2
    @HanyHabib - I suspect the answer is going to be something along the lines of the unwritten requirement in the question - that what the OP has failed to mention is that want it to be *tamper resistant*. And then we go down the usual lines of how this is nigh-unsolvable when code is running on the *users* machine. – Damien_The_Unbeliever May 21 '18 at 08:41
  • or the pc name, the user login name, the user SID, config file, a unique registry value that you generate, ect ect ect – TheGeneral May 21 '18 at 08:43
  • Ok let me explain, my program is used to control your pc with a web interface so lets say i got 1 user on my website that has 2 computers. He would need an executable made for him with his user id that is in the database of my website. But what if i got another user and many more, i need to make thousands of versions of my program. Also my program needs to be just the exe and the config filw can be tweaked by the user which i don't like them doing – DavidAnastasov May 21 '18 at 08:43
  • 1
    Exactly, don't make 1000s of versions, this is x/y – TheGeneral May 21 '18 at 08:44
  • If you really really really want to go down this path, create a standard windows dll, with a guid or 64 bit int or something, find the offset and modify it on demand before deplyment... however you are better to solve this otherways, especially if you are using a webapi or wcf capable service anyway, its how everyone else does it – TheGeneral May 21 '18 at 08:50
  • My website is mostly html with php so i was going to upload that form i mentioned above and let the user compile his own executable, confirming his id with a password of course. Do i have to go this route or is there a way to do it in backend and give executable to user. Also i need the program in exe not dll – DavidAnastasov May 21 '18 at 08:56
  • you could use `msbuild` backend, but this still is a very very uncommon why to do things, it just doesn't make sense – TheGeneral May 21 '18 at 09:02
  • Can you give me some examples or point me to the right direction where to start looking for this – DavidAnastasov May 21 '18 at 09:08

1 Answers1

1

I think your idea isn't very good, but you made a specific request, so I'll give you a specific response.

If your program is msbuildable, then simply executing

msbuild yoursolution.sln /p:Configuration=Release /p:Platform="Any CPU"

(I'm using the Release/AnyCPU here, but you'll have to use the correct parameters depending on how you normally compile your solution)

through the System.Diagnostics.Process.Start method will big a big step in the right direction.

Clearly before doing it you modify a .cs file or a resource that will be included in the program.

Now... the only problem is that with newer Visual Studio/.NET the msbuild.exe location can change. The simplest way to solve it is to find it manually, for example open a Visual Studio Command Prompt and do:

where msbuild.exe

the first path is the one that would be executed if you used the msbuild.exe from that command prompt, or use the instructions given here

xanatos
  • 109,618
  • 12
  • 197
  • 280
  • ok this can work, but can it be done on a html website backend so it is done automatically? – DavidAnastasov May 21 '18 at 09:11
  • @DavidAnastasov You must have the Platform SDK installed in the backend to be able to compile... There is no need of special permissions to use the msbuild – xanatos May 21 '18 at 09:12
  • @DavidAnastasov The simplest thing is that first you try to compile the program with msbuild from a command prompt, see what are the parameters needed and when everything work you try using the `Process.Start` – xanatos May 21 '18 at 09:13
  • @xanatox i saw u implemented p:Configuration and p:Platform, i know these come with evey solution but can i add something like p:UserID= for my project or is it not possible? – DavidAnastasov May 21 '18 at 09:15
  • 1
    @DavidAnastasov It is easier to modify a source file/a resource file... You can modify a csproj so that the UserID will be written somewhere, but it is black magic :-) much easier to directly modify the files. This is probably a good starting point if you want to know about this black magic: https://stackoverflow.com/q/3585444/613130 – xanatos May 21 '18 at 09:16
  • yeah man this is amazing, thanks for your help u solved an issue i had for a long time :) – DavidAnastasov May 21 '18 at 09:30