|
Add the issuer as a trusted issuer on the client side. That is what is done in development and testing purposes. You don't need to get a certificate for development environment. Certificates matter when you are publishing the product.
On development environment, you just have to mimic the process. It can be done by either adding your own issuer (a software program) as a trusted one. Otherwise, ignore the request, which sadly cannot be done when the function always throws an exception.
Working with Certificates[^]
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
I saw a simple example from microsoft "How to: Populate an XML Tree from the File System (C#)".
But I cant figure out how to reverse the XML to get a list of all files with full qualified path simular to "dir /s /b" would produce:
Tmp\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe<br />
Size: 4608<br />
Tmp\ConsoleApplication1\bin\Debug\ConsoleApplication1.vshost.exe.manifest<br />
Size: 473<br />
Tmp\ConsoleApplication1\obj\Debug\TempPE\ConsoleApplication1.csproj.FileListAbsolute.txt<br />
Size: 322<br />
... and so on<br />
Can somone help with this?
Example from MSDN:
class Program
{
static XElement CreateFileSystemXmlTree(string source)
{
DirectoryInfo di = new DirectoryInfo(source);
return new XElement("Dir",
new XAttribute("Name", di.Name),
from d in Directory.GetDirectories(source)
select CreateFileSystemXmlTree(d),
from fi in di.GetFiles()
select new XElement("File",
new XElement("Name", fi.Name),
new XElement("Length", fi.Length)
)
);
}
static void Main(string[] args)
{
XElement fileSystemTree = CreateFileSystemXmlTree("C:/Tmp");
Console.WriteLine(fileSystemTree);
Console.WriteLine("------");
long totalFileSize =
(from f in fileSystemTree.Descendants("File")
select (long)f.Element("Length")).Sum();
Console.WriteLine("Total File Size:{0}", totalFileSize);
}
}
<Dir Name="Tmp">
<Dir Name="ConsoleApplication1">
<Dir Name="bin">
<Dir Name="Debug">
<File>
<Name>ConsoleApplication1.exe</Name>
<Length>4608</Length>
</File>
<File>
<Name>ConsoleApplication1.pdb</Name>
<Length>11776</Length>
</File>
<File>
<Name>ConsoleApplication1.vshost.exe</Name>
<Length>9568</Length>
</File>
<File>
<Name>ConsoleApplication1.vshost.exe.manifest</Name>
<Length>473</Length>
</File>
</Dir>
</Dir>
<Dir Name="obj">
<Dir Name="Debug">
<Dir Name="TempPE" />
<File>
<Name>ConsoleApplication1.csproj.FileListAbsolute.txt</Name>
<Length>322</Length>
</File>
<File>
<Name>ConsoleApplication1.exe</Name>
<Length>4608</Length>
</File>
<File>
<Name>ConsoleApplication1.pdb</Name>
<Length>11776</Length>
</File>
</Dir>
</Dir>
<Dir Name="Properties">
<File>
<Name>AssemblyInfo.cs</Name>
<Length>1454</Length>
</File>
</Dir>
<File>
<Name>ConsoleApplication1.csproj</Name>
<Length>2546</Length>
</File>
<File>
<Name>ConsoleApplication1.sln</Name>
<Length>937</Length>
</File>
<File>
<Name>ConsoleApplication1.suo</Name>
<Length>10752</Length>
</File>
<File>
<Name>Program.cs</Name>
<Length>269</Length>
</File>
</Dir>
</Dir>
------
Total File Size:59089
|
|
|
|
|
use FullName instead of Name
new XElement("Name", fi.FullName),
|
|
|
|
|
But that brings up next problem: You get the full path + filename.
First of all I am realy serious in finding out if there is a way to reverse the
new XElement("Name", fi.Name), version.
Secondly I want it relative to the starting path.
Maybe that was not clear. Lets say you have resulting XML (part ofthe example):
<Dir Name="Tmp">
<Dir Name="ConsoleApplication1">
<Dir Name="bin">
<Dir Name="Debug">
<File>
<Name>ConsoleApplication1.exe</Name>
<Length>4608</Length>
</File>
</Dir>
</Dir>
</Dir>
</Dir>
I want to read the results:
File.Name: temp\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe
File.Length: 4608
Without the c:\.
Advantage: if you move all from c:\Temp to c:\Projects\Temp you can still find all files as in the XML if you revers the search.
Greetings
modified 22-May-16 16:55pm.
|
|
|
|
|
 I played around and did a realy dirty and probably inefficent solution for the problem (SHA256 was additionally added to XML):
using (var reader = new XmlTextReader(@"c:\Users\andre\Documents\Test3.xml"))
{
List<string> myDir = new List<string>();
bool isFile = false;
bool isFileName = false;
bool isSHA = false;
bool isLength = false;
string curFile = "";
string curLength = "";
string curSHA = "";
while (reader.Read())
{
switch (reader.NodeType)
{
case XmlNodeType.XmlDeclaration:
break;
case XmlNodeType.Element:
if (reader.Name.ToString().Equals("Dir",StringComparison.OrdinalIgnoreCase))
{
myDir.Add(reader.GetAttribute("Name"));
isFile = false;
}
else if (reader.Name.ToString().Equals("File", StringComparison.OrdinalIgnoreCase))
{
isFile = true;
}
else if (reader.Name.ToString().Equals("Name", StringComparison.OrdinalIgnoreCase))
{
if (isFile)
{
isFileName = true;
}
else
{
Console.WriteLine("error on Line {0} Name <{1}> Value{2}",reader.LineNumber,reader.Name,reader.Value);
}
}
else if (reader.Name.ToString().Equals("Length", StringComparison.OrdinalIgnoreCase))
{
if (isFile)
{
isLength = true;
}
else
{
Console.WriteLine("error on Line {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
}
}
else if (reader.Name.ToString().Equals("SHA256", StringComparison.OrdinalIgnoreCase))
{
if (isFile)
{
isSHA = true;
}
else
{
Console.WriteLine("error on Line {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
}
}
else
{
Console.WriteLine("Unknown Element {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
}
break;
case XmlNodeType.Text:
if (isFileName)
{
curFile = reader.Value;
}
else if (isSHA){
curSHA = reader.Value;
}
else if (isLength)
{
curLength = reader.Value;
}
else
{
Console.WriteLine("Unknown Text Line {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
}
break;
case XmlNodeType.EndElement:
if (reader.Name.ToString().Equals("dir", StringComparison.OrdinalIgnoreCase))
{
myDir.Remove(myDir.Last());
isFile = false;
}
else if (reader.Name.ToString().Equals("File", StringComparison.OrdinalIgnoreCase))
{
isFile = false;
Console.WriteLine("Path: {0}",string.Join("\\", myDir.ToArray()));
if (!curSHA.Equals("")) {
Console.WriteLine(" File: {0} Length: {1} SHA256: {2}",curFile,curLength,curSHA);
}
else
{
Console.WriteLine(" File: {0} Length: {1}", curFile, curLength);
}
}
else if (reader.Name.ToString().Equals("Length", StringComparison.OrdinalIgnoreCase))
{
isLength = false;
}
else if (reader.Name.ToString().Equals("SHA256", StringComparison.OrdinalIgnoreCase))
{
isSHA = false;
}
else if (reader.Name.ToString().Equals("Name", StringComparison.OrdinalIgnoreCase))
{
isFileName = false;
}
else {
Console.WriteLine("Unknown End element {0} Name <{1}> Value{2}", reader.LineNumber, reader.Name, reader.Value);
}
break;
}
}
}
(Note: string.Join()-Line destroys coloring)
Even it is not nice as it's not mucht better than just textparsing and manual decoding the XML , it works:
Path: Tmp\ConsoleApplication1\bin\Debug
File: ConsoleApplication1.exe Length: 4608
Path: Tmp\ConsoleApplication1\bin\Debug
File: ConsoleApplication1.pdb Length: 11776
Path: Tmp\ConsoleApplication1\bin\Debug
File: ConsoleApplication1.vshost.exe Length: 9568
Path: Tmp\ConsoleApplication1\bin\Debug
File: ConsoleApplication1.vshost.exe.manifest Length: 473
Path: Tmp\ConsoleApplication1\obj\Debug\TempPE
File: ConsoleApplication1.csproj.FileListAbsolute.txt Length: 322
Path: Tmp\ConsoleApplication1\obj\Debug\TempPE
File: ConsoleApplication1.exe Length: 4608
Path: Tmp\ConsoleApplication1\obj\Debug\TempPE
File: ConsoleApplication1.pdb Length: 11776
Path: Tmp\ConsoleApplication1\obj\Properties
File: AssemblyInfo.cs Length: 1454
Path: Tmp\ConsoleApplication1\obj
File: ConsoleApplication1.csproj Length: 2546
Path: Tmp\ConsoleApplication1\obj
File: ConsoleApplication1.sln Length: 937
Path: Tmp\ConsoleApplication1\obj
File: ConsoleApplication1.suo Length: 10752
Path: Tmp\ConsoleApplication1\obj
File: Program.cs Length: 269
If anyone has a better solution: youre welcome!!!
I'm still serious if theres not a easyser solution to revert back this (my current test) 1-Liner:
return new XElement("Dir",
new XAttribute("Name", di.Name),
from d in Directory.GetDirectories(source)
select CreateFileSystemXmlTree(d, progress),
from fi in di.GetFiles()
let myProgress = DoProgress(progress)
select new XElement("File",
new XElement("Name", fi.Name),
new XElement("Length", fi.Length),
new XElement("SHA256", GetChecksumBuffered(fi.FullName))
)
);
|
|
|
|
|
Member 2443306 wrote: myDir.Remove(myDir.Last());
myDir.RemoveAt(myDir.Count - 1); would be more efficient, and avoid a bug if multiple directories in the path have the same name (eg: Tmp\Path\Tmp\... ).
Better yet, replace the List<T> with Stack<T>[^], which is specifically designed for this type of scenario.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Aiks!!!
Thanks I overseen the problem with
myDir.Remove() against
myDir.RemoveAt(myDir.Count-1) .
I changed it to
Stack<T> but not realy see a advabntage.
|
|
|
|
|
|
Why not ask on the forum at the end of article? It's highly unlikely that the author is going to happen on this post?
This space for rent
|
|
|
|
|
The article was deleted in March 2015.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
No. If you look at the non-archived version[^], you'll see that the article was deleted in March 2015, and the source code was removed at the request of Mladen's employers.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
We got hit with that windows 10 upgrade today on 1/2 the computers.
So I wrote a console app to apply a tweak to Win 7 to stop the upgrades.
When I go to delete the folder with the disk image of Win10, I get an error saying this is a special file. How can I skip the error?
This is my first console app, and I'm new to c#
public static bool delete_win10Source(string winPath)
{
bool pValue = false;
try
{
DirectoryInfo dir = new DirectoryInfo(@winPath);
bool rV = dir.Exists;
if (rV)
Task.Factory.StartNew(path => dir.Delete(true), winPath);
pValue = true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
pValue = false;
}
return pValue;
}
|
|
|
|
|
Is it "speacial or just write protected?
I'm not shure but maybe something like this?
var directory = new DirectoryInfo(@winPath);
directory.Attributes &= ~FileAttributes.ReadOnly;
|
|
|
|
|
I need to run the program on a win7 machine again to see the message. I have a win8.1 machine.
Give me a day to do this, time to go home.
|
|
|
|
|
Guess my idea to just write a program to disable win10 upgrades was not a good idea.
Just FYI, the 2nd key is what the group policy does from what I read.
I can't access the LocalMachine Key, I just get a null back.
I did the click run as administrator.
Logged in as administrator.
I really don't want to manually adjust every computer in the office.
Guess Microsoft really tightened up the security which is good.
public static bool tweak_registry()
{
bool pValue = false;
const string subKey1 = "SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\OSUpgrade";
const string keyName1 = "AllowOSUpgrade";
const string keyName2 = "DisableOSUpgrade";
try
{
using (var _key = Registry.LocalMachine.OpenSubKey(subKey1, true))
{
_key.SetValue(keyName1, 0, RegistryValueKind.DWord);
_key.SetValue(keyName2, 1, RegistryValueKind.DWord);
}
pValue = true;
}
catch (Exception ex)
{
pValue = false;
if (ex.Message == "Attempted to perform an unauthorized operation.")
{
Console.WriteLine("");
Console.WriteLine("You must be an adminsitrator to perform this task!");
Console.WriteLine("Right Click on the program and select 'Run as Administrator'");
Console.WriteLine("Press any key to exit");
Console.ReadKey();
System.Environment.Exit(-1);
}
else
{
Console.WriteLine("ERROR: " + ex.Message);
Console.ReadKey();
}
}
return pValue;
}
|
|
|
|
|
Visual Studio? You have "AnyCPU as target?
As far as I know to access the registry with "AnyCPU" you need to take care of 32 and 64bit on the SOFTWARE key.
|
|
|
|
|
I just ran into that with running dsim, seems there's 2 of them.
I'll look into that!
Thanks
|
|
|
|
|
I didn't know that Any CPU had 2 different views of the registry, and calling programs like DSIM.
So I got that part working now for file execution and registry, but even elevating the UAC didn't allow me to edit that value and add a key.
Thanks for pointing that out to me!
|
|
|
|
|
Well I got 80% of what I wanted. Deployed it today on 14 machines. Just took 30 minutes.
The console program was a good experience for me. At least removing the updates was easy.
|
|
|
|
|
|
can I kowth the way to make slide panel dotnetbar tutorial c#
sliding pannel effects.... 
|
|
|
|
|
What's a dotnetbar?
This space for rent
|
|
|
|
|
An Internet Cafe in Yorkshire?
(Do T'Net Bar)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|